1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-20 00:38:00 +01:00
Files
pentadactyl-pm/common/content/browser.js
Kris Maglione 1557b70f45 Major documentation updates and formatting fixes, and many, many other changes thanks to an MQ glitch, including:
* Significant completion speed improvements
 * Significantly improve startup speed, in large part by lazily
   instantiating Options and Commands, lazily installing highlight
   stylesheets, etc.
 * Update logos and icons, fix atrocious about page
 * Fix Teledactyl
 * JavaScript completion now avoids accessing property values
 * Add Option#persist to define which options are saved with :mkp
 * Add new Dactyl component which holds add-on-specific configuration
   information and removes need for separate components for each dactyl
   host
 * Several fixes for latest nightlies
 * Significant code cleanup and many bug fixes

--HG--
rename : muttator/AUTHORS => teledactyl/AUTHORS
rename : muttator/Donors => teledactyl/Donors
rename : muttator/Makefile => teledactyl/Makefile
rename : muttator/NEWS => teledactyl/NEWS
rename : muttator/TODO => teledactyl/TODO
rename : muttator/chrome.manifest => teledactyl/chrome.manifest
rename : muttator/components/commandline-handler.js => teledactyl/components/commandline-handler.js
rename : muttator/components/protocols.js => teledactyl/components/protocols.js
rename : muttator/content/addressbook.js => teledactyl/content/addressbook.js
rename : muttator/content/compose/compose.js => teledactyl/content/compose/compose.js
rename : muttator/content/compose/compose.xul => teledactyl/content/compose/compose.xul
rename : muttator/content/compose/dactyl.dtd => teledactyl/content/compose/dactyl.dtd
rename : muttator/content/compose/dactyl.xul => teledactyl/content/compose/dactyl.xul
rename : muttator/content/config.js => teledactyl/content/config.js
rename : muttator/content/dactyl.dtd => teledactyl/content/dactyl.dtd
rename : muttator/content/logo.png => teledactyl/content/logo.png
rename : muttator/content/mail.js => teledactyl/content/mail.js
rename : muttator/content/muttator.xul => teledactyl/content/pentadactyl.xul
rename : muttator/contrib/vim/Makefile => teledactyl/contrib/vim/Makefile
rename : muttator/contrib/vim/ftdetect/muttator.vim => teledactyl/contrib/vim/ftdetect/muttator.vim
rename : muttator/contrib/vim/mkvimball.txt => teledactyl/contrib/vim/mkvimball.txt
rename : muttator/contrib/vim/syntax/muttator.vim => teledactyl/contrib/vim/syntax/muttator.vim
rename : muttator/install.rdf => teledactyl/install.rdf
rename : muttator/locale/en-US/Makefile => teledactyl/locale/en-US/Makefile
rename : muttator/locale/en-US/all.xml => teledactyl/locale/en-US/all.xml
rename : muttator/locale/en-US/autocommands.xml => teledactyl/locale/en-US/autocommands.xml
rename : muttator/locale/en-US/gui.xml => teledactyl/locale/en-US/gui.xml
rename : muttator/locale/en-US/intro.xml => teledactyl/locale/en-US/intro.xml
rename : muttator/skin/icon.png => teledactyl/skin/icon.png
2010-09-17 06:21:33 -04:00

201 lines
7.5 KiB
JavaScript

// Copyright (c) 2006-2008 by Martin Stubenschrott <stubenschrott@vimperator.org>
// Copyright (c) 2007-2009 by Doug Kearns <dougkearns@gmail.com>
// Copyright (c) 2008-2010 by Kris Maglione <maglione.k at Gmail>
//
// This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file.
"use strict";
/** @scope modules */
/**
* @instance browser
*/
const Browser = Module("browser", {
}, {
// TODO: support 'nrformats'? -> probably not worth it --mst
incrementURL: function (count) {
let matches = buffer.URL.match(/(.*?)(\d+)(\D*)$/);
dactyl.assert(matches);
let [, pre, number, post] = matches;
let newNumber = parseInt(number, 10) + count;
let newNumberStr = String(newNumber > 0 ? newNumber : 0);
if (number.match(/^0/)) { // add 0009<C-a> should become 0010
while (newNumberStr.length < number.length)
newNumberStr = "0" + newNumberStr;
}
dactyl.open(pre + newNumberStr + post);
}
}, {
options: function () {
options.add(["encoding", "enc"],
"Sets the current buffer's character encoding",
"string", "UTF-8",
{
scope: Option.SCOPE_LOCAL,
getter: function () config.browser.docShell.QueryInterface(Ci.nsIDocCharset).charset,
setter: function (val) {
if (options["encoding"] == val)
return val;
// Stolen from browser.jar/content/browser/browser.js, more or less.
try {
config.browser.docShell.QueryInterface(Ci.nsIDocCharset).charset = val;
PlacesUtils.history.setCharsetForURI(getWebNavigation().currentURI, val);
getWebNavigation().reload(Ci.nsIWebNavigation.LOAD_FLAGS_CHARSET_CHANGE);
}
catch (e) { dactyl.reportError(e); }
return null;
},
completer: function (context) completion.charset(context)
});
options.add(["urlseparator"],
"Set the separator regex used to separate multiple URL args",
"string", ",\\s");
},
mappings: function () {
mappings.add([modes.NORMAL],
["y"], "Yank current location to the clipboard",
function () { dactyl.clipboardWrite(buffer.URL, true); });
// opening websites
mappings.add([modes.NORMAL],
["o"], "Open one or more URLs",
function () { commandline.open(":", "open ", modes.EX); });
mappings.add([modes.NORMAL], ["O"],
"Open one or more URLs, based on current location",
function () { commandline.open(":", "open " + buffer.URL, modes.EX); });
mappings.add([modes.NORMAL], ["t"],
"Open one or more URLs in a new tab",
function () { commandline.open(":", "tabopen ", modes.EX); });
mappings.add([modes.NORMAL], ["T"],
"Open one or more URLs in a new tab, based on current location",
function () { commandline.open(":", "tabopen " + buffer.URL, modes.EX); });
mappings.add([modes.NORMAL], ["w"],
"Open one or more URLs in a new window",
function () { commandline.open(":", "winopen ", modes.EX); });
mappings.add([modes.NORMAL], ["W"],
"Open one or more URLs in a new window, based on current location",
function () { commandline.open(":", "winopen " + buffer.URL, modes.EX); });
mappings.add([modes.NORMAL],
["<C-a>"], "Increment last number in URL",
function (count) { Browser.incrementURL(Math.max(count, 1)); },
{ count: true });
mappings.add([modes.NORMAL],
["<C-x>"], "Decrement last number in URL",
function (count) { Browser.incrementURL(-Math.max(count, 1)); },
{ count: true });
mappings.add([modes.NORMAL], ["~"],
"Open home directory",
function () { dactyl.open("~"); });
mappings.add([modes.NORMAL], ["gh"],
"Open homepage",
function () { BrowserHome(); });
mappings.add([modes.NORMAL], ["gH"],
"Open homepage in a new tab",
function () {
let homepages = gHomeButton.getHomePage();
dactyl.open(homepages, { from: "homepage", where: dactyl.NEW_TAB });
});
mappings.add([modes.NORMAL], ["gu"],
"Go to parent directory",
function (count) {
function isDirectory(url) {
if (/^file:\/|^\//.test(url)) {
let file = io.File(url);
return file.exists() && file.isDirectory();
}
else {
// for all other locations just check if the URL ends with /
return /\/$/.test(url);
}
}
if (count < 1)
count = 1;
// XXX
let url = buffer.URL;
for (let i = 0; i < count; i++) {
if (isDirectory(url))
url = url.replace(/^(.*?:)(.*?)([^\/]+\/*)$/, "$1$2/");
else
url = url.replace(/^(.*?:)(.*?)(\/+[^\/]+)$/, "$1$2/");
}
url = url.replace(/^(.*:\/+.*?)\/+$/, "$1/"); // get rid of more than 1 / at the end
if (url == buffer.URL)
dactyl.beep();
else
dactyl.open(url);
},
{ count: true });
mappings.add([modes.NORMAL], ["gU"],
"Go to the root of the website",
function () {
let uri = content.document.location;
dactyl.assert(!/(about|mailto):/.test(uri.protocol)); // exclude these special protocols for now
dactyl.open(uri.protocol + "//" + (uri.host || "") + "/");
});
mappings.add([modes.NORMAL], ["<C-l>"],
"Redraw the screen",
function () { commands.get("redraw").execute("", false); });
},
commands: function () {
commands.add(["downl[oads]", "dl"],
"Show progress of current downloads",
function () {
dactyl.open("chrome://mozapps/content/downloads/downloads.xul",
{ from: "downloads"});
},
{ argCount: "0" });
commands.add(["o[pen]"],
"Open one or more URLs in the current tab",
function (args) {
args = args.string;
if (args)
dactyl.open(args);
else
dactyl.open("about:blank");
}, {
completer: function (context) completion.url(context),
domains: function (args) array.compact(dactyl.stringToURLArray(args[0] || "").map(
function (url) util.getHost(url))),
literal: 0,
privateData: true
});
commands.add(["redr[aw]"],
"Redraw the screen",
function () {
let wu = window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
wu.redraw();
modes.show();
},
{ argCount: "0" });
}
});
// vim: set fdm=marker sw=4 ts=4 et: