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

prefer let over var in Buffer and Marks

This commit is contained in:
Doug Kearns
2008-12-09 00:16:13 +11:00
parent 01b7484986
commit d20578b2a0

View File

@@ -84,7 +84,7 @@ function Buffer() //{{{
function findScrollableWindow() function findScrollableWindow()
{ {
var win = window.document.commandDispatcher.focusedWindow; let win = window.document.commandDispatcher.focusedWindow;
if (win && (win.scrollMaxX > 0 || win.scrollMaxY > 0)) if (win && (win.scrollMaxX > 0 || win.scrollMaxY > 0))
return win; return win;
@@ -102,8 +102,8 @@ function Buffer() //{{{
// both values are given in percent, -1 means no change // both values are given in percent, -1 means no change
function scrollToPercentiles(horizontal, vertical) function scrollToPercentiles(horizontal, vertical)
{ {
var win = findScrollableWindow(); let win = findScrollableWindow();
var h, v; let h, v;
if (horizontal < 0) if (horizontal < 0)
h = win.scrollX; h = win.scrollX;
@@ -330,8 +330,8 @@ function Buffer() //{{{
} }
else else
{ {
var elements = []; let elements = [];
var matches = buffer.evaluateXPath( let matches = buffer.evaluateXPath(
// TODO: type="file" // TODO: type="file"
"//input[not(@type) or @type='text' or @type='password'] | //textarea[not(@disabled) and not(@readonly)] |" + "//input[not(@type) or @type='text' or @type='password'] | //textarea[not(@disabled) and not(@readonly)] |" +
"//xhtml:input[not(@type) or @type='text' or @type='password'] | //xhtml:textarea[not(@disabled) and not(@readonly)]" "//xhtml:input[not(@type) or @type='text' or @type='password'] | //xhtml:textarea[not(@disabled) and not(@readonly)]"
@@ -397,7 +397,8 @@ function Buffer() //{{{
"Copy selected text or current word", "Copy selected text or current word",
function () function ()
{ {
var sel = buffer.getCurrentWord(); let sel = buffer.getCurrentWord();
if (sel) if (sel)
util.copyToClipboard(sel, true); util.copyToClipboard(sel, true);
else else
@@ -473,8 +474,8 @@ function Buffer() //{{{
"Print current document", "Print current document",
function (args) function (args)
{ {
var aps = options.getPref("print.always_print_silent"); let aps = options.getPref("print.always_print_silent");
var spp = options.getPref("print.show_print_progress"); let spp = options.getPref("print.show_print_progress");
liberator.echomsg("Sending to printer..."); liberator.echomsg("Sending to printer...");
options.setPref("print.always_print_silent", args.bang); options.setPref("print.always_print_silent", args.bang);
@@ -509,7 +510,7 @@ function Buffer() //{{{
{ {
args = args.string; args = args.string;
var titles = buffer.alternateStyleSheets.map(function (stylesheet) stylesheet.title); let titles = buffer.alternateStyleSheets.map(function (stylesheet) stylesheet.title);
if (args && titles.indexOf(args) == -1) if (args && titles.indexOf(args) == -1)
{ {
@@ -768,7 +769,7 @@ function Buffer() //{{{
yield ["Title", doc.title]; yield ["Title", doc.title];
yield ["URL", template.highlightURL(doc.location.toString(), true)]; yield ["URL", template.highlightURL(doc.location.toString(), true)];
var ref = "referrer" in doc && doc.referrer; let ref = "referrer" in doc && doc.referrer;
if (ref) if (ref)
yield ["Referrer", template.highlightURL(ref, true)]; yield ["Referrer", template.highlightURL(ref, true)];
@@ -786,7 +787,7 @@ function Buffer() //{{{
addPageInfoSection("m", "Meta Tags", function (verbose) addPageInfoSection("m", "Meta Tags", function (verbose)
{ {
// 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"); let metaNodes = window.content.document.getElementsByTagName("meta");
return Array.map(metaNodes, function (node) [(node.name || node.httpEquiv), template.highlightURL(node.content)]) return Array.map(metaNodes, function (node) [(node.name || node.httpEquiv), template.highlightURL(node.content)])
.sort(function (a, b) util.compareIgnoreCase(a[0], b[0])); .sort(function (a, b) util.compareIgnoreCase(a[0], b[0]));
@@ -800,7 +801,7 @@ function Buffer() //{{{
get alternateStyleSheets() get alternateStyleSheets()
{ {
var stylesheets = window.getAllStyleSheets(window.content); let stylesheets = window.getAllStyleSheets(window.content);
return stylesheets.filter( return stylesheets.filter(
function (stylesheet) /^(screen|all|)$/i.test(stylesheet.media.mediaText) && !/^\s*$/.test(stylesheet.title) function (stylesheet) /^(screen|all|)$/i.test(stylesheet.media.mediaText) && !/^\s*$/.test(stylesheet.title)
@@ -878,7 +879,7 @@ function Buffer() //{{{
if (!elem) if (!elem)
elem = doc; elem = doc;
var result = doc.evaluate(expression, elem, let result = doc.evaluate(expression, elem,
function lookupNamespaceURI(prefix) function lookupNamespaceURI(prefix)
{ {
switch (prefix) switch (prefix)
@@ -941,9 +942,9 @@ function Buffer() //{{{
elem.focus(); elem.focus();
var evt = doc.createEvent("MouseEvents"); let evt = doc.createEvent("MouseEvents");
var x = 0; let x = 0;
var y = 0; let y = 0;
// for imagemap // for imagemap
if (elemTagName == "area") if (elemTagName == "area")
[x, y] = elem.getAttribute("coords").split(",").map(Number); [x, y] = elem.getAttribute("coords").split(",").map(Number);
@@ -1011,12 +1012,12 @@ function Buffer() //{{{
// artificially "clicks" a link in order to open it // artificially "clicks" a link in order to open it
followLink: function (elem, where) followLink: function (elem, where)
{ {
var doc = elem.ownerDocument; let doc = elem.ownerDocument;
var view = doc.defaultView; let view = doc.defaultView;
var offsetX = 1; let offsetX = 1;
var offsetY = 1; let offsetY = 1;
var localName = elem.localName.toLowerCase(); let localName = elem.localName.toLowerCase();
if (localName == "frame" || localName == "iframe") // broken? if (localName == "frame" || localName == "iframe") // broken?
{ {
elem.contentWindow.focus(); elem.contentWindow.focus();
@@ -1024,12 +1025,12 @@ function Buffer() //{{{
} }
else if (localName == "area") // for imagemap else if (localName == "area") // for imagemap
{ {
var coords = elem.getAttribute("coords").split(","); let coords = elem.getAttribute("coords").split(",");
offsetX = Number(coords[0]) + 1; offsetX = Number(coords[0]) + 1;
offsetY = Number(coords[1]) + 1; offsetY = Number(coords[1]) + 1;
} }
var ctrlKey = false, shiftKey = false; let ctrlKey = false, shiftKey = false;
switch (where) switch (where)
{ {
case liberator.NEW_TAB: case liberator.NEW_TAB:
@@ -1048,7 +1049,7 @@ function Buffer() //{{{
elem.focus(); elem.focus();
var evt = doc.createEvent("MouseEvents"); let evt = doc.createEvent("MouseEvents");
["mousedown", "mouseup", "click"].forEach(function (event) { ["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);
@@ -1063,9 +1064,9 @@ function Buffer() //{{{
saveLink: function (elem, skipPrompt) saveLink: function (elem, skipPrompt)
{ {
var doc = elem.ownerDocument; let doc = elem.ownerDocument;
var url = window.makeURLAbsolute(elem.baseURI, elem.href); let url = window.makeURLAbsolute(elem.baseURI, elem.href);
var text = elem.textContent; let text = elem.textContent;
try try
{ {
@@ -1087,7 +1088,7 @@ function Buffer() //{{{
scrollColumns: function (cols) scrollColumns: function (cols)
{ {
var win = findScrollableWindow(); let win = findScrollableWindow();
const COL_WIDTH = 20; const COL_WIDTH = 20;
if (cols > 0 && win.scrollX >= win.scrollMaxX || cols < 0 && win.scrollX == 0) if (cols > 0 && win.scrollX >= win.scrollMaxX || cols < 0 && win.scrollX == 0)
@@ -1103,14 +1104,14 @@ function Buffer() //{{{
scrollLines: function (lines) scrollLines: function (lines)
{ {
var win = findScrollableWindow(); let win = findScrollableWindow();
checkScrollYBounds(win, lines); checkScrollYBounds(win, lines);
win.scrollByLines(lines); win.scrollByLines(lines);
}, },
scrollPages: function (pages) scrollPages: function (pages)
{ {
var win = findScrollableWindow(); let win = findScrollableWindow();
checkScrollYBounds(win, pages); checkScrollYBounds(win, pages);
win.scrollByPages(pages); win.scrollByPages(pages);
}, },
@@ -1120,7 +1121,7 @@ function Buffer() //{{{
if (count > 0) if (count > 0)
options["scroll"] = count; options["scroll"] = count;
var win = findScrollableWindow(); let win = findScrollableWindow();
checkScrollYBounds(win, direction); checkScrollYBounds(win, direction);
if (options["scroll"] > 0) if (options["scroll"] > 0)
@@ -1151,7 +1152,7 @@ function Buffer() //{{{
return; return;
count = Math.max(count, 1); count = Math.max(count, 1);
var frames = []; let frames = [];
// find all frames - depth-first search // find all frames - depth-first search
(function (frame) { (function (frame) {
@@ -1165,7 +1166,7 @@ function Buffer() //{{{
// remove all unfocusable frames // remove all unfocusable frames
// TODO: find a better way to do this - walking the tree is too slow // TODO: find a better way to do this - walking the tree is too slow
var start = document.commandDispatcher.focusedWindow; let start = document.commandDispatcher.focusedWindow;
frames = frames.filter(function (frame) { frames = frames.filter(function (frame) {
frame.focus(); frame.focus();
return document.commandDispatcher.focusedWindow == frame; return document.commandDispatcher.focusedWindow == frame;
@@ -1177,10 +1178,10 @@ function Buffer() //{{{
// focused. Since this is not the current FF behaviour, // focused. Since this is not the current FF behaviour,
// we initalize current to -1 so the first call takes us to the // we initalize current to -1 so the first call takes us to the
// first frame. // first frame.
var current = frames.indexOf(document.commandDispatcher.focusedWindow); let current = frames.indexOf(document.commandDispatcher.focusedWindow);
// calculate the next frame to focus // calculate the next frame to focus
var next = current; let next = current;
if (forward) if (forward)
{ {
next = current + count; next = current + count;
@@ -1211,7 +1212,7 @@ function Buffer() //{{{
// add the frame indicator // add the frame indicator
let doc = frames[next].document; let doc = frames[next].document;
var indicator = util.xmlToDom(<div highlight="FrameIndicator"/>, doc); let indicator = util.xmlToDom(<div highlight="FrameIndicator"/>, doc);
doc.body.appendChild(indicator); doc.body.appendChild(indicator);
setTimeout(function () { doc.body.removeChild(indicator); }, 500); setTimeout(function () { doc.body.removeChild(indicator); }, 500);
@@ -1243,7 +1244,7 @@ function Buffer() //{{{
if (bookmarks.isBookmarked(this.URL)) if (bookmarks.isBookmarked(this.URL))
info += ", bookmarked"; info += ", bookmarked";
var pageInfoText = <>"{file}" [{info}] {title}</>; let pageInfoText = <>"{file}" [{info}] {title}</>;
liberator.echo(pageInfoText, commandline.FORCE_SINGLELINE); liberator.echo(pageInfoText, commandline.FORCE_SINGLELINE);
return; return;
} }
@@ -1260,18 +1261,18 @@ function Buffer() //{{{
viewSelectionSource: function () viewSelectionSource: function ()
{ {
// copied (and tuned somebit) from browser.jar -> nsContextMenu.js // copied (and tuned somebit) from browser.jar -> nsContextMenu.js
var focusedWindow = document.commandDispatcher.focusedWindow; let focusedWindow = document.commandDispatcher.focusedWindow;
if (focusedWindow == window) if (focusedWindow == window)
focusedWindow = content; focusedWindow = content;
var docCharset = null; let docCharset = null;
if (focusedWindow) if (focusedWindow)
docCharset = "charset=" + focusedWindow.document.characterSet; docCharset = "charset=" + focusedWindow.document.characterSet;
var reference = null; let reference = null;
reference = focusedWindow.getSelection(); reference = focusedWindow.getSelection();
var docUrl = null; let docUrl = null;
window.openDialog("chrome://global/content/viewPartialSource.xul", window.openDialog("chrome://global/content/viewPartialSource.xul",
"_blank", "scrollbars,resizable,chrome,dialog=no", "_blank", "scrollbars,resizable,chrome,dialog=no",
docUrl, docCharset, reference, "selection"); docUrl, docCharset, reference, "selection");
@@ -1317,10 +1318,10 @@ function Marks() //{{{
function onPageLoad(event) function onPageLoad(event)
{ {
var win = event.originalTarget.defaultView; let win = event.originalTarget.defaultView;
for (let i = 0, length = pendingJumps.length; i < length; i++) for (let i = 0, length = pendingJumps.length; i < length; i++)
{ {
var mark = pendingJumps[i]; let mark = pendingJumps[i];
if (win && win.location.href == mark.location) if (win && win.location.href == mark.location)
{ {
win.scrollTo(mark.position.x * win.scrollMaxX, mark.position.y * win.scrollMaxY); win.scrollTo(mark.position.x * win.scrollMaxX, mark.position.y * win.scrollMaxY);
@@ -1340,10 +1341,10 @@ function Marks() //{{{
function removeLocalMark(mark) function removeLocalMark(mark)
{ {
var localmark = localMarks.get(mark); let localmark = localMarks.get(mark);
if (localmark) if (localmark)
{ {
var win = window.content; let win = window.content;
for (let [i,] in Iterator(localmark)) for (let [i,] in Iterator(localmark))
{ {
if (localmark[i].location == win.location.href) if (localmark[i].location == win.location.href)
@@ -1360,7 +1361,7 @@ function Marks() //{{{
function removeURLMark(mark) function removeURLMark(mark)
{ {
var urlmark = urlMarks.get(mark); let urlmark = urlMarks.get(mark);
if (urlmark) if (urlmark)
{ {
liberator.log("Deleting URL mark: " + markToString(mark, urlmark), 5); liberator.log("Deleting URL mark: " + markToString(mark, urlmark), 5);
@@ -1440,7 +1441,7 @@ function Marks() //{{{
liberator.echoerr("E474: Invalid argument"); liberator.echoerr("E474: Invalid argument");
return; return;
} }
var matches; let matches;
if (matches = args.match(/(?:(?:^|[^a-zA-Z0-9])-|-(?:$|[^a-zA-Z0-9])|[^a-zA-Z0-9 -]).*/)) if (matches = args.match(/(?:(?:^|[^a-zA-Z0-9])-|-(?:$|[^a-zA-Z0-9])|[^a-zA-Z0-9 -]).*/))
{ {
// NOTE: this currently differs from Vim's behavior which // NOTE: this currently differs from Vim's behavior which
@@ -1454,8 +1455,8 @@ function Marks() //{{{
{ {
for (let i = 0; i < matches.length; i++) for (let i = 0; i < matches.length; i++)
{ {
var start = matches[i][0]; let start = matches[i][0];
var end = matches[i][2]; let end = matches[i][2];
if (/[a-z]/.test(start) != /[a-z]/.test(end) || if (/[a-z]/.test(start) != /[a-z]/.test(end) ||
/[A-Z]/.test(start) != /[A-Z]/.test(end) || /[A-Z]/.test(start) != /[A-Z]/.test(end) ||
/[0-9]/.test(start) != /[0-9]/.test(end) || /[0-9]/.test(start) != /[0-9]/.test(end) ||
@@ -1475,7 +1476,7 @@ function Marks() //{{{
"Mark current location within the web page", "Mark current location within the web page",
function (args) function (args)
{ {
var mark = args[0]; let mark = args[0];
if (mark.length > 1) if (mark.length > 1)
{ {
liberator.echoerr("E488: Trailing characters"); liberator.echoerr("E488: Trailing characters");
@@ -1504,7 +1505,7 @@ function Marks() //{{{
return; return;
} }
var filter = args.replace(/[^a-zA-Z]/g, ""); let filter = args.replace(/[^a-zA-Z]/g, "");
marks.list(filter); marks.list(filter);
}); });
@@ -1517,7 +1518,7 @@ function Marks() //{{{
// TODO: add support for frameset pages // TODO: add support for frameset pages
add: function (mark) add: function (mark)
{ {
var win = window.content; let win = window.content;
if (win.document.body.localName.toLowerCase() == "frameset") if (win.document.body.localName.toLowerCase() == "frameset")
{ {
@@ -1525,9 +1526,9 @@ function Marks() //{{{
return; return;
} }
var x = win.scrollMaxX ? win.pageXOffset / win.scrollMaxX : 0; let x = win.scrollMaxX ? win.pageXOffset / win.scrollMaxX : 0;
var y = win.scrollMaxY ? win.pageYOffset / win.scrollMaxY : 0; let y = win.scrollMaxY ? win.pageYOffset / win.scrollMaxY : 0;
var position = { x: x, y: y }; let position = { x: x, y: y };
if (isURLMark(mark)) if (isURLMark(mark))
{ {
@@ -1556,7 +1557,7 @@ function Marks() //{{{
} }
else else
{ {
var pattern = new RegExp("[" + filter.replace(/\s+/g, "") + "]"); let pattern = new RegExp("[" + filter.replace(/\s+/g, "") + "]");
for (let [mark,] in urlMarks) for (let [mark,] in urlMarks)
{ {
if (pattern.test(mark)) if (pattern.test(mark))
@@ -1572,7 +1573,7 @@ function Marks() //{{{
jumpTo: function (mark) jumpTo: function (mark)
{ {
var ok = false; let ok = false;
if (isURLMark(mark)) if (isURLMark(mark))
{ {
@@ -1587,11 +1588,11 @@ function Marks() //{{{
liberator.open(slice.location, liberator.NEW_TAB); liberator.open(slice.location, liberator.NEW_TAB);
return; return;
} }
var index = tabs.index(slice.tab); let index = tabs.index(slice.tab);
if (index != -1) if (index != -1)
{ {
tabs.select(index); tabs.select(index);
var win = slice.tab.linkedBrowser.contentWindow; let win = slice.tab.linkedBrowser.contentWindow;
if (win.location.href != slice.location) if (win.location.href != slice.location)
{ {
pendingJumps.push(slice); pendingJumps.push(slice);
@@ -1627,7 +1628,7 @@ function Marks() //{{{
list: function (filter) list: function (filter)
{ {
var marks = getSortedMarks(); let marks = getSortedMarks();
if (marks.length == 0) if (marks.length == 0)
{ {