1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-23 04:47:59 +01:00

merge :paginfo output refinements

This commit is contained in:
Doug Kearns
2007-11-13 05:58:05 +00:00
parent b204ef96f1
commit 0f9951e048
2 changed files with 74 additions and 42 deletions

View File

@@ -165,7 +165,7 @@ vimperator.Buffer = function () //{{{
); );
return result; return result;
} };
this.list = function (fullmode) this.list = function (fullmode)
{ {
@@ -212,12 +212,12 @@ vimperator.Buffer = function () //{{{
vimperator.commandline.echo(list, vimperator.commandline.HL_NORMAL, vimperator.commandline.FORCE_MULTILINE); vimperator.commandline.echo(list, vimperator.commandline.HL_NORMAL, vimperator.commandline.FORCE_MULTILINE);
} }
} };
this.scrollBottom = function () this.scrollBottom = function ()
{ {
scrollToPercentiles(-1, 100); scrollToPercentiles(-1, 100);
} };
this.scrollColumns = function (cols) this.scrollColumns = function (cols)
{ {
@@ -228,41 +228,41 @@ vimperator.Buffer = function () //{{{
vimperator.beep(); vimperator.beep();
win.scrollBy(COL_WIDTH * cols, 0); win.scrollBy(COL_WIDTH * cols, 0);
} };
this.scrollEnd = function () this.scrollEnd = function ()
{ {
scrollToPercentiles(100, -1); scrollToPercentiles(100, -1);
} };
this.scrollLines = function (lines) this.scrollLines = function (lines)
{ {
var win = window.document.commandDispatcher.focusedWindow; var win = window.document.commandDispatcher.focusedWindow;
checkScrollYBounds(win, lines); checkScrollYBounds(win, lines);
win.scrollByLines(lines); win.scrollByLines(lines);
} };
this.scrollPages = function (pages) this.scrollPages = function (pages)
{ {
var win = window.document.commandDispatcher.focusedWindow; var win = window.document.commandDispatcher.focusedWindow;
checkScrollYBounds(win, pages); checkScrollYBounds(win, pages);
win.scrollByPages(pages); win.scrollByPages(pages);
} };
this.scrollToPercentile = function (percentage) this.scrollToPercentile = function (percentage)
{ {
scrollToPercentiles(-1, percentage); scrollToPercentiles(-1, percentage);
} };
this.scrollStart = function () this.scrollStart = function ()
{ {
scrollToPercentiles(0, -1); scrollToPercentiles(0, -1);
} };
this.scrollTop = function () this.scrollTop = function ()
{ {
scrollToPercentiles(-1, 0); scrollToPercentiles(-1, 0);
} };
// TODO: allow callback for filtering out unwanted frames? User defined? // TODO: allow callback for filtering out unwanted frames? User defined?
this.shiftFrameFocus = function (count, forward) this.shiftFrameFocus = function (count, forward)
@@ -361,7 +361,7 @@ vimperator.Buffer = function () //{{{
// remove the frame indicator // remove the frame indicator
setTimeout(function () { doc.body.removeChild(indicator); }, 500); setTimeout(function () { doc.body.removeChild(indicator); }, 500);
} };
// updates the buffer preview in place only if list is visible // updates the buffer preview in place only if list is visible
this.updateBufferList = function () this.updateBufferList = function ()
@@ -372,7 +372,7 @@ vimperator.Buffer = function () //{{{
var items = vimperator.completion.get_buffer_completions(""); var items = vimperator.completion.get_buffer_completions("");
vimperator.bufferwindow.show(items); vimperator.bufferwindow.show(items);
vimperator.bufferwindow.selectItem(getBrowser().mTabContainer.selectedIndex); vimperator.bufferwindow.selectItem(getBrowser().mTabContainer.selectedIndex);
} };
// XXX: should this be in v.buffers. or v.tabs.? // XXX: should this be in v.buffers. or v.tabs.?
// "buffer" is a string which matches the URL or title of a buffer, if it // "buffer" is a string which matches the URL or title of a buffer, if it
@@ -437,23 +437,23 @@ vimperator.Buffer = function () //{{{
this.zoomIn = function (steps) this.zoomIn = function (steps)
{ {
bumpZoomLevel(steps); bumpZoomLevel(steps);
} };
this.zoomOut = function (steps) this.zoomOut = function (steps)
{ {
bumpZoomLevel(-steps); bumpZoomLevel(-steps);
} };
this.pageInfo = function (verbose) this.pageInfo = function (verbose)
{ {
// TODO: copied from firefox. Needs some review/work... const feedTypes = {
// const feedTypes = { "application/rss+xml": "RSS",
// "application/rss+xml": gBundle.getString("feedRss"), "application/atom+xml": "Atom",
// "application/atom+xml": gBundle.getString("feedAtom"), "text/xml": "XML",
// "text/xml": gBundle.getString("feedXML"), "application/xml": "XML",
// "application/xml": gBundle.getString("feedXML"), "application/rdf+xml": "XML"
// "application/rdf+xml": gBundle.getString("feedXML") };
// };
function isValidFeed(aData, aPrincipal, aIsFeed) function isValidFeed(aData, aPrincipal, aIsFeed)
{ {
if (!aData || !aPrincipal) if (!aData || !aPrincipal)
@@ -541,8 +541,10 @@ vimperator.Buffer = function () //{{{
var pageSize = []; // [0] bytes; [1] kbytes var pageSize = []; // [0] bytes; [1] kbytes
if (cacheEntryDescriptor) if (cacheEntryDescriptor)
{ {
pageSize[0] = vimperator.util.formatNumber(cacheEntryDescriptor.dataSize); pageSize[0] = vimperator.util.formatBytes(cacheEntryDescriptor.dataSize, 0, false);
pageSize[1] = vimperator.util.formatNumber(Math.round(cacheEntryDescriptor.dataSize / 1024 * 100) / 100); pageSize[1] = vimperator.util.formatBytes(cacheEntryDescriptor.dataSize, 2, true);
if (pageSize[1] == pageSize[0])
pageSize[1] = null; // don't output "xx Bytes" twice
} }
// put feeds rss into pageFeeds[] // put feeds rss into pageFeeds[]
@@ -567,13 +569,18 @@ vimperator.Buffer = function () //{{{
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, window.content.document.nodePrincipal, rels.feed))
{ {
// var type = feedTypes[feed.type] || feedTypes["application/rss+xml"]; // TODO: dig into that.. --calmar var type = feedTypes[feed.type] || feedTypes["application/rss+xml"];
var type = feed.type || "application/rss+xml"; pageFeeds.push([feed.title, vimperator.util.highlightURL(feed.href, true) + " (" + type + ")"]);
pageFeeds.push([feed.title, vimperator.util.highlightURL(feed.href, true)]);
} }
} }
} }
var lastModVerbose = new Date(window.content.document.lastModified).toLocaleString();
var lastMod = new Date(window.content.document.lastModified).toLocaleFormat("%x %X");
// FIXME: probably unportable across differnet language versions
if (lastModVerbose == "Invalid Date")
lastModVerbose = lastMod = null;
// Ctrl-g single line output // Ctrl-g single line output
if (!verbose) if (!verbose)
{ {
@@ -581,10 +588,9 @@ vimperator.Buffer = function () //{{{
var file = window.content.document.location.pathname.split("/").pop() || "[No Name]"; var file = window.content.document.location.pathname.split("/").pop() || "[No Name]";
var title = window.content.document.title || "[No Title]"; var title = window.content.document.title || "[No Title]";
if (pageSize[1]) if (pageSize[0])
info.push(pageSize[1] + "KiB"); info.push(pageSize[1] || pageSize[0]);
var lastMod = window.content.document.lastModified.slice(0, -3);
if (lastMod) if (lastMod)
info.push(lastMod); info.push(lastMod);
@@ -609,12 +615,18 @@ vimperator.Buffer = function () //{{{
pageGeneral.push(["Referrer", vimperator.util.highlightURL(ref, true)]); pageGeneral.push(["Referrer", vimperator.util.highlightURL(ref, true)]);
if (pageSize[0]) if (pageSize[0])
pageGeneral.push(["File Size", pageSize[1] + "KiB (" + pageSize[0] + " bytes)"]); {
if (pageSize[1])
pageGeneral.push(["File Size", pageSize[1] + " (" + pageSize[0] + ")"]);
else
pageGeneral.push(["File Size", pageSize[0]]);
}
pageGeneral.push(["Mime-Type", window.content.document.contentType]); pageGeneral.push(["Mime-Type", content.document.contentType]);
pageGeneral.push(["Encoding", window.content.document.characterSet]); pageGeneral.push(["Encoding", content.document.characterSet]);
pageGeneral.push(["Compatibility", content.document.compatMode == "BackCompat" ? "Quirks Mode" : "Full/Almost Standards Mode"]); pageGeneral.push(["Compatibility", content.document.compatMode == "BackCompat" ? "Quirks Mode" : "Full/Almost Standards Mode"]);
pageGeneral.push(["Last Modified", window.content.document.lastModified]); //TODO: do not show bogus times (=current time) if (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 = window.content.document.getElementsByTagName("meta");
@@ -677,7 +689,7 @@ vimperator.Buffer = function () //{{{
} }
} }
vimperator.echo(pageInfoText, vimperator.commandline.FORCE_MULTILINE); vimperator.echo(pageInfoText, vimperator.commandline.FORCE_MULTILINE);
} };
//}}} //}}}
} //}}} } //}}}

View File

@@ -166,18 +166,38 @@ vimperator.util = {
return str; return str;
}, },
formatNumber: function (num) formatBytes: function (num, decimalPlaces, humanReadable)
{ {
var strNum = (num + "").split(".", 2); const unitVal = ["Bytes", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"];
var unitIndex = 0;
var tmpNum = parseInt(num) || 0;
var strNum = [tmpNum + ""];
for (var u = strNum[0].length - 3; u > 0; u -= 3) if (humanReadable)
{
while (tmpNum >= 1024)
{
tmpNum /= 1024;
if (++unitIndex > (unitVal.length - 1))
break;
}
let decPower = Math.pow(10, decimalPlaces);
strNum = ((Math.round(tmpNum * decPower) / decPower) + "").split(".", 2);
if (!strNum[1])
strNum[1] = "";
while (strNum[1].length < decimalPlaces) // padd with "0" to the desired decimalPlaces)
strNum[1] += "0";
}
for (var u = strNum[0].length - 3; u > 0; u -= 3) // make a 10000 a 10,000
strNum[0] = strNum[0].substring(0, u) + "," + strNum[0].substring(u, strNum[0].length); strNum[0] = strNum[0].substring(0, u) + "," + strNum[0].substring(u, strNum[0].length);
if (strNum[1]) if (unitIndex) // decimalPlaces only when > Bytes
strNum[0] += "." + strNum[1] strNum[0] += "." + strNum[1];
return strNum[0]; return strNum[0] + " " + unitVal[unitIndex];
} }
} };
// vim: set fdm=marker sw=4 ts=4 et: // vim: set fdm=marker sw=4 ts=4 et: