diff --git a/content/addressbook.js b/content/addressbook.js index 3813efac..56602e14 100644 --- a/content/addressbook.js +++ b/content/addressbook.js @@ -26,7 +26,7 @@ the provisions above, a recipient may use your version of this file under the terms of any one of the MPL, the GPL or the LGPL. }}} ***** END LICENSE BLOCK *****/ -liberator.Addressbook = function () //{{{ +with (liberator) liberator.Addressbook = function () //{{{ { //////////////////////////////////////////////////////////////////////////////// ////////////////////// PRIVATE SECTION ///////////////////////////////////////// @@ -71,9 +71,9 @@ liberator.Addressbook = function () //{{{ ////////////////////// MAPPINGS //////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ - var modes = liberator.config.mailModes || [liberator.modes.NORMAL]; + var myModes = config.mailModes || [modes.NORMAL]; - liberator.mappings.add(modes, ["a"], + mappings.add(myModes, ["a"], "Open a prompt to save a new addressbook entry for the sender of the selected message", function () { @@ -84,7 +84,7 @@ liberator.Addressbook = function () //{{{ } catch (e) { - liberator.beep(); + beep(); } if (!to) @@ -104,14 +104,14 @@ liberator.Addressbook = function () //{{{ displayName = "-name=\"" + displayName.replace(/"/g, "") + "\""; } - liberator.commandline.open(":", "contact " + address + " " + displayName, liberator.modes.EX); + commandline.open(":", "contact " + address + " " + displayName, modes.EX); }); /////////////////////////////////////////////////////////////////////////////}}} ////////////////////// COMMANDS //////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ - liberator.commands.add(["con[tact]"], + commands.add(["con[tact]"], "Add an address book entry", function (args) { @@ -122,22 +122,22 @@ liberator.Addressbook = function () //{{{ if (!displayName) displayName = generateDisplayName(firstName, lastName); - if (liberator.addressbook.add(mailAddr, firstName, lastName, displayName)) - liberator.echo("Added address: " + displayName + " <" + mailAddr + ">", liberator.commandline.FORCE_SINGLELINE); + if (addressbook.add(mailAddr, firstName, lastName, displayName)) + echo("Added address: " + displayName + " <" + mailAddr + ">", commandline.FORCE_SINGLELINE); else - liberator.echoerr("Exxx: Could not add bookmark `" + mailAddr + "'", liberator.commandline.FORCE_SINGLELINE); + echoerr("Exxx: Could not add bookmark `" + mailAddr + "'", commandline.FORCE_SINGLELINE); }, { argCount: "+", - options: [[["-firstname", "-f"], liberator.commands.OPTION_STRING], - [["-lastname", "-l"], liberator.commands.OPTION_STRING], - [["-name", "-n"], liberator.commands.OPTION_STRING]] + options: [[["-firstname", "-f"], commands.OPTION_STRING], + [["-lastname", "-l"], commands.OPTION_STRING], + [["-name", "-n"], commands.OPTION_STRING]] }); - liberator.commands.add(["contacts", "addr[essbook]"], + commands.add(["contacts", "addr[essbook]"], "List or open multiple addresses", - function (args, special) { liberator.addressbook.list(args, special); }, + function (args, special) { addressbook.list(args, special); }, { bang: true }); /////////////////////////////////////////////////////////////////////////////}}} @@ -189,7 +189,7 @@ liberator.Addressbook = function () //{{{ } if (addresses.length < 1) { - liberator.echoerr("E94: No matching contact for " + filter, liberator.commandline.FORCE_SINGLELINE); + echoerr("E94: No matching contact for " + filter, commandline.FORCE_SINGLELINE); return false; } @@ -201,21 +201,21 @@ liberator.Addressbook = function () //{{{ function (address) "\"" + address[0].replace(/"/g, "") + " <" + address[1] + ">\"" ).join(", "); - liberator.mail.composeNewMail(args); + mail.composeNewMail(args); } else { - var list = ":" + liberator.util.escapeHTML(liberator.commandline.getCommand()) + "
" + + var list = ":" + util.escapeHTML(commandline.getCommand()) + "
" + ""; for (let i = 0; i < addresses.length; i++) { - var displayName = liberator.util.escapeHTML(liberator.util.clip(addresses[i][0], 50)); - var mailAddr = liberator.util.escapeHTML(addresses[i][1]); + var displayName = util.escapeHTML(util.clip(addresses[i][0], 50)); + var mailAddr = util.escapeHTML(addresses[i][1]); list += ""; } list += "
NameAddress
" + displayName + "" + mailAddr + "
"; - liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); + commandline.echo(list, commandline.HL_NORMAL, commandline.FORCE_MULTILINE); } return true; } diff --git a/content/bookmarks.js b/content/bookmarks.js index aba4446b..63fe9a13 100644 --- a/content/bookmarks.js +++ b/content/bookmarks.js @@ -27,7 +27,7 @@ the terms of any one of the MPL, the GPL or the LGPL. }}} ***** END LICENSE BLOCK *****/ // also includes methods for dealing with keywords and search engines -liberator.Bookmarks = function () //{{{ +with (liberator) liberator.Bookmarks = function () //{{{ { //////////////////////////////////////////////////////////////////////////////// ////////////////////// PRIVATE SECTION ///////////////////////////////////////// @@ -43,8 +43,8 @@ liberator.Bookmarks = function () //{{{ const faviconService = Components.classes["@mozilla.org/browser/favicon-service;1"] .getService(Components.interfaces.nsIFaviconService); - const Bookmark = new liberator.util.Struct("url", "title", "icon", "keyword", "tags", "id"); - const Keyword = new liberator.util.Struct("keyword", "title", "icon", "url"); + const Bookmark = new util.Struct("url", "title", "icon", "keyword", "tags", "id"); + const Keyword = new util.Struct("keyword", "title", "icon", "url"); const storage = liberator.storage; function Cache(name, store, serial) @@ -100,7 +100,7 @@ liberator.Bookmarks = function () //{{{ this.load = function load() { - // liberator.dump("cache.load()\n"); + // dump("cache.load()\n"); // update our bookmark cache bookmarks = []; this.__defineGetter__("bookmarks", function () bookmarks); @@ -141,7 +141,7 @@ liberator.Bookmarks = function () //{{{ onItemMoved: function () {}, onItemAdded: function (itemId, folder, index) { - // liberator.dump("onItemAdded(" + itemId + ", " + folder + ", " + index + ")\n"); + // dump("onItemAdded(" + itemId + ", " + folder + ", " + index + ")\n"); if (bookmarksService.getItemType(itemId) == bookmarksService.TYPE_BOOKMARK) { if (rootFolders.indexOf(findRoot(itemId)) >= 0) @@ -153,7 +153,7 @@ liberator.Bookmarks = function () //{{{ }, onItemRemoved: function (itemId, folder, index) { - // liberator.dump("onItemRemoved(" + itemId + ", " + folder + ", " + index + ")\n"); + // dump("onItemRemoved(" + itemId + ", " + folder + ", " + index + ")\n"); if (deleteBookmark(itemId)) storage.fireEvent(name, "remove", itemId); }, @@ -161,7 +161,7 @@ liberator.Bookmarks = function () //{{{ { if (isAnnotation) return; - // liberator.dump("onItemChanged(" + itemId + ", " + property + ", " + value + ")\n"); + // dump("onItemChanged(" + itemId + ", " + property + ", " + value + ")\n"); var bookmark = bookmarks.filter(function (item) item.id == itemId)[0]; if (bookmark) { @@ -186,18 +186,18 @@ liberator.Bookmarks = function () //{{{ let bookmarkObserver = function (key, event, arg) { if (event == "add") - liberator.autocommands.trigger("BookmarkAdd", arg); - liberator.statusline.updateUrl(); + autocommands.trigger("BookmarkAdd", arg); + statusline.updateUrl(); } - var cache = liberator.storage.newObject("bookmark-cache", Cache, false); - liberator.storage.addObserver("bookmark-cache", bookmarkObserver); - liberator.registerObserver("shutdown", function () { - liberator.storage.removeObserver("bookmark-cache", bookmarkObserver) + var cache = storage.newObject("bookmark-cache", Cache, false); + storage.addObserver("bookmark-cache", bookmarkObserver); + registerObserver("shutdown", function () { + storage.removeObserver("bookmark-cache", bookmarkObserver) }); - liberator.registerObserver("enter", function () { - if (liberator.options["preload"]) + registerObserver("enter", function () { + if (options["preload"]) cache.bookmarks; // Forces a load, if not already loaded. }); @@ -205,18 +205,18 @@ liberator.Bookmarks = function () //{{{ ////////////////////// OPTIONS ///////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ - liberator.options.add(["defsearch", "ds"], + options.add(["defsearch", "ds"], "Set the default search engine", "string", "google", { - completer: function (filter) liberator.completion.url("", "s")[1], + completer: function (filter) completion.url("", "s")[1], validator: function (value) { - return liberator.completion.url("", "s")[1].some(function (s) s[0] == value); + return completion.url("", "s")[1].some(function (s) s[0] == value); } }); - liberator.options.add(["preload"], + options.add(["preload"], "Speed up first time history/bookmark completion", "boolean", true); @@ -224,87 +224,87 @@ liberator.Bookmarks = function () //{{{ ////////////////////// MAPPINGS //////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ - var modes = liberator.config.browserModes || [liberator.modes.NORMAL]; + var myModes = config.browserModes || [modes.NORMAL]; - liberator.mappings.add(modes, ["a"], + mappings.add(myModes, ["a"], "Open a prompt to bookmark the current URL", function () { var title = ""; - if (liberator.buffer.title != liberator.buffer.URL) - title = " -title=\"" + liberator.buffer.title + "\""; - liberator.commandline.open(":", "bmark " + liberator.buffer.URL + title, liberator.modes.EX); + if (buffer.title != buffer.URL) + title = " -title=\"" + buffer.title + "\""; + commandline.open(":", "bmark " + buffer.URL + title, modes.EX); }); - liberator.mappings.add(modes, ["A"], + mappings.add(myModes, ["A"], "Toggle bookmarked state of current URL", - function () { liberator.bookmarks.toggle(liberator.buffer.URL); }); + function () { bookmarks.toggle(buffer.URL); }); /////////////////////////////////////////////////////////////////////////////}}} ////////////////////// COMMANDS //////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ - liberator.commands.add(["ju[mps]"], + commands.add(["ju[mps]"], "Show jumplist", function () { var sh = getWebNavigation().sessionHistory; - let entries = [sh.getEntryAtIndex(i, false) for (i in liberator.util.range(0, sh.count))]; - let list = liberator.template.jumps(sh.index, entries); - liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); + let entries = [sh.getEntryAtIndex(i, false) for (i in util.range(0, sh.count))]; + let list = template.jumps(sh.index, entries); + commandline.echo(list, commandline.HL_NORMAL, commandline.FORCE_MULTILINE); }, { argCount: "0" }); - liberator.commands.add(["bma[rk]"], + commands.add(["bma[rk]"], "Add a bookmark", function (args, special) { - var url = args.arguments.length == 0 ? liberator.buffer.URL : args.arguments[0]; - var title = args["-title"] || (args.arguments.length == 0 ? liberator.buffer.title : null); + var url = args.arguments.length == 0 ? buffer.URL : args.arguments[0]; + var title = args["-title"] || (args.arguments.length == 0 ? buffer.title : null); var keyword = args["-keyword"] || null; var tags = args["-tags"] || []; - if (liberator.bookmarks.add(false, title, url, keyword, tags, special)) + if (bookmarks.add(false, title, url, keyword, tags, special)) { var extra = ""; if (title != url) extra = " (" + title + ")"; - liberator.echo("Added bookmark: " + url + extra, liberator.commandline.FORCE_SINGLELINE); + echo("Added bookmark: " + url + extra, commandline.FORCE_SINGLELINE); } else - liberator.echoerr("Exxx: Could not add bookmark `" + title + "'", liberator.commandline.FORCE_SINGLELINE); + echoerr("Exxx: Could not add bookmark `" + title + "'", commandline.FORCE_SINGLELINE); }, { argCount: "?", bang: true, - options: [[["-title", "-t"], liberator.commands.OPTION_STRING], - [["-tags", "-T"], liberator.commands.OPTION_LIST], - [["-keyword", "-k"], liberator.commands.OPTION_STRING, function (arg) /\w/.test(arg)]] + options: [[["-title", "-t"], commands.OPTION_STRING], + [["-tags", "-T"], commands.OPTION_LIST], + [["-keyword", "-k"], commands.OPTION_STRING, function (arg) /\w/.test(arg)]] }); - liberator.commands.add(["bmarks"], + commands.add(["bmarks"], "List or open multiple bookmarks", function (args, special) { - liberator.bookmarks.list(args.arguments.join(" "), args["-tags"] || [], special); + bookmarks.list(args.arguments.join(" "), args["-tags"] || [], special); }, { bang: true, - completer: function (filter) liberator.completion.bookmark(filter), - options: [[["-tags", "-T"], liberator.commands.OPTION_LIST]] + completer: function (filter) completion.bookmark(filter), + options: [[["-tags", "-T"], commands.OPTION_LIST]] }); - liberator.commands.add(["delbm[arks]"], + commands.add(["delbm[arks]"], "Delete a bookmark", function (args) { - let url = args || liberator.buffer.URL; - let deletedCount = liberator.bookmarks.remove(url); + let url = args || buffer.URL; + let deletedCount = bookmarks.remove(url); - liberator.echo(deletedCount + " bookmark(s) with url `" + url + "' deleted", liberator.commandline.FORCE_SINGLELINE); + echo(deletedCount + " bookmark(s) with url `" + url + "' deleted", commandline.FORCE_SINGLELINE); }, - { completer: function (filter) liberator.completion.bookmark(filter) }); + { completer: function (filter) completion.bookmark(filter) }); /////////////////////////////////////////////////////////////////////////////}}} ////////////////////// PUBLIC SECTION ////////////////////////////////////////// @@ -319,7 +319,7 @@ liberator.Bookmarks = function () //{{{ { if (bypassCache) // Is this really necessary anymore? cache.load(); - return liberator.completion.cached("bookmarks", filter, function () cache.bookmarks, + return completion.cached("bookmarks", filter, function () cache.bookmarks, "filterURLArray", tags); }, @@ -328,7 +328,7 @@ liberator.Bookmarks = function () //{{{ { try { - var uri = liberator.util.createURI(url); + var uri = util.createURI(url); if (!force) { for (let bmark in cache) @@ -356,7 +356,7 @@ liberator.Bookmarks = function () //{{{ } catch (e) { - liberator.log(e, 0); + log(e, 0); return false; } @@ -371,16 +371,16 @@ liberator.Bookmarks = function () //{{{ var count = this.remove(url); if (count > 0) { - liberator.commandline.echo("Removed bookmark: " + url, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_SINGLELINE); + commandline.echo("Removed bookmark: " + url, commandline.HL_NORMAL, commandline.FORCE_SINGLELINE); } else { - var title = liberator.buffer.title || url; + var title = buffer.title || url; var extra = ""; if (title != url) extra = " (" + title + ")"; this.add(true, title, url); - liberator.commandline.echo("Added bookmark: " + url + extra, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_SINGLELINE); + commandline.echo("Added bookmark: " + url + extra, commandline.HL_NORMAL, commandline.FORCE_SINGLELINE); } }, @@ -415,12 +415,12 @@ liberator.Bookmarks = function () //{{{ } catch (e) { - liberator.log(e, 0); + log(e, 0); return i; } // update the display of our "bookmarked" symbol - liberator.statusline.updateUrl(); + statusline.updateUrl(); return count.value; }, @@ -474,7 +474,7 @@ liberator.Bookmarks = function () //{{{ { var url = null; var aPostDataRef = {}; - var searchString = (useDefsearch? liberator.options["defsearch"] + " " : "") + text; + var searchString = (useDefsearch? options["defsearch"] + " " : "") + text; // we need to make sure our custom alias have been set, even if the user // did not :open once before @@ -497,21 +497,21 @@ liberator.Bookmarks = function () //{{{ if (items.length == 0) { if (filter.length > 0 && tags.length > 0) - liberator.echoerr("E283: No bookmarks matching tags: \"" + tags + "\" and string: \"" + filter + "\""); + echoerr("E283: No bookmarks matching tags: \"" + tags + "\" and string: \"" + filter + "\""); else if (filter.length > 0) - liberator.echoerr("E283: No bookmarks matching string: \"" + filter + "\""); + echoerr("E283: No bookmarks matching string: \"" + filter + "\""); else if (tags.length > 0) - liberator.echoerr("E283: No bookmarks matching tags: \"" + tags + "\""); + echoerr("E283: No bookmarks matching tags: \"" + tags + "\""); else - liberator.echoerr("No bookmarks set"); + echoerr("No bookmarks set"); return; } if (openItems) - return liberator.open([i.url for each (i in items)], liberator.NEW_TAB); + return open([i.url for each (i in items)], NEW_TAB); - let list = liberator.template.bookmarks("title", ( + let list = template.bookmarks("title", ( { url: item.url, title: item.title, @@ -519,13 +519,13 @@ liberator.Bookmarks = function () //{{{ ['tags', item.tags.join(', '), "hl-Tag"] ].filter(function (i) i[1]) } for each (item in items))); - liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); + commandline.echo(list, commandline.HL_NORMAL, commandline.FORCE_MULTILINE); }, }; //}}} }; //}}} -liberator.History = function () //{{{ +with (liberator) liberator.History = function () //{{{ { //////////////////////////////////////////////////////////////////////////////// ////////////////////// PRIVATE SECTION ///////////////////////////////////////// @@ -562,7 +562,7 @@ liberator.History = function () //{{{ for (let i = 0; i < rootNode.childCount; i++) { var node = rootNode.getChild(i); - // liberator.dump("History child " + node.itemId + ": " + node.title + " - " + node.type); + // dump("History child " + node.itemId + ": " + node.title + " - " + node.type); if (node.type == node.RESULT_TYPE_URI) // just make sure it's a bookmark history.push([node.uri, node.title || "[No title]", getIcon(node.uri)]); } @@ -571,8 +571,8 @@ liberator.History = function () //{{{ rootNode.containerOpen = false; } - liberator.registerObserver("enter", function () { - if (liberator.options["preload"]) + registerObserver("enter", function () { + if (options["preload"]) load(); }); @@ -580,39 +580,39 @@ liberator.History = function () //{{{ ////////////////////// MAPPINGS //////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ - var modes = liberator.config.browserModes || [liberator.modes.NORMAL]; + var myModes = config.browserModes || [modes.NORMAL]; - liberator.mappings.add(modes, + mappings.add(myModes, [""], "Go to an older position in the jump list", - function (count) { liberator.history.stepTo(-(count > 1 ? count : 1)); }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { history.stepTo(-(count > 1 ? count : 1)); }, + { flags: Mappings.flags.COUNT }); - liberator.mappings.add(modes, + mappings.add(myModes, [""], "Go to a newer position in the jump list", - function (count) { liberator.history.stepTo(count > 1 ? count : 1); }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { history.stepTo(count > 1 ? count : 1); }, + { flags: Mappings.flags.COUNT }); - liberator.mappings.add(modes, + mappings.add(myModes, ["H", "", ""], "Go back in the browser history", - function (count) { liberator.history.stepTo(-(count > 1 ? count : 1)); }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { history.stepTo(-(count > 1 ? count : 1)); }, + { flags: Mappings.flags.COUNT }); - liberator.mappings.add(modes, + mappings.add(myModes, ["L", "", ""], "Go forward in the browser history", - function (count) { liberator.history.stepTo(count > 1 ? count : 1); }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { history.stepTo(count > 1 ? count : 1); }, + { flags: Mappings.flags.COUNT }); /////////////////////////////////////////////////////////////////////////////}}} ////////////////////// COMMANDS //////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ - liberator.commands.add(["ba[ck]"], + commands.add(["ba[ck]"], "Go back in the browser history", function (args, special, count) { if (special) { - liberator.history.goToStart(); + history.goToStart(); } else { @@ -627,11 +627,11 @@ liberator.History = function () //{{{ return; } } - liberator.echoerr("Exxx: URL not found in history"); + echoerr("Exxx: URL not found in history"); } else { - liberator.history.stepTo(count > 0 ? -1 * count : -1); + history.stepTo(count > 0 ? -1 * count : -1); } } }, @@ -646,7 +646,7 @@ liberator.History = function () //{{{ var entry = sh.getEntryAtIndex(i, false); var url = entry.URI.spec; var title = entry.title; - if (liberator.completion.match([url, title], filter, false)) + if (completion.match([url, title], filter, false)) completions.push([url, title]); } return [0, completions]; @@ -654,13 +654,13 @@ liberator.History = function () //{{{ count: true }); - liberator.commands.add(["fo[rward]", "fw"], + commands.add(["fo[rward]", "fw"], "Go forward in the browser history", function (args, special, count) { if (special) { - liberator.history.goToEnd(); + history.goToEnd(); } else { @@ -675,11 +675,11 @@ liberator.History = function () //{{{ return; } } - liberator.echoerr("Exxx: URL not found in history"); + echoerr("Exxx: URL not found in history"); } else { - liberator.history.stepTo(count > 0 ? count : 1); + history.stepTo(count > 0 ? count : 1); } } }, @@ -694,7 +694,7 @@ liberator.History = function () //{{{ var entry = sh.getEntryAtIndex(i, false); var url = entry.URI.spec; var title = entry.title; - if (liberator.completion.match([url, title], filter, false)) + if (completion.match([url, title], filter, false)) completions.push([url, title]); } return [0, completions]; @@ -702,12 +702,12 @@ liberator.History = function () //{{{ count: true }); - liberator.commands.add(["hist[ory]", "hs"], + commands.add(["hist[ory]", "hs"], "Show recently visited URLs", - function (args, special) { liberator.history.list(args, special); }, + function (args, special) { history.list(args, special); }, { bang: true, - completer: function (filter) liberator.completion.history(filter) + completer: function (filter) completion.history(filter) }); /////////////////////////////////////////////////////////////////////////////}}} @@ -723,7 +723,7 @@ liberator.History = function () //{{{ if (!filter) return cachedHistory.concat(history); - return liberator.completion.cached("history", filter, function () cachedHistory.concat(history), + return completion.cached("history", filter, function () cachedHistory.concat(history), "filterURLArray"); }, @@ -751,7 +751,7 @@ liberator.History = function () //{{{ }, // TODO: better names? - // and move to liberator.buffer.? + // and move to buffer.? stepTo: function (steps) { var index = getWebNavigation().sessionHistory.index + steps; @@ -762,7 +762,7 @@ liberator.History = function () //{{{ } else { - liberator.beep(); + beep(); } }, @@ -772,7 +772,7 @@ liberator.History = function () //{{{ if (index == 0) { - liberator.beep(); + beep(); return; } @@ -786,7 +786,7 @@ liberator.History = function () //{{{ if (index == max) { - liberator.beep(); + beep(); return; } @@ -800,129 +800,129 @@ liberator.History = function () //{{{ if (items.length == 0) { if (filter.length > 0) - liberator.echoerr("E283: No history matching \"" + filter + "\""); + echoerr("E283: No history matching \"" + filter + "\""); else - liberator.echoerr("No history set"); + echoerr("No history set"); return; } if (openItems) { - return liberator.open([i[0] for each (i in items)], liberator.NEW_TAB); + return open([i[0] for each (i in items)], NEW_TAB); } else { - let list = liberator.template.bookmarks("title", ( + let list = template.bookmarks("title", ( { title: item[1], url: item[0], } for each (item in items))); - liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); + commandline.echo(list, commandline.HL_NORMAL, commandline.FORCE_MULTILINE); } } }; //}}} }; //}}} -liberator.QuickMarks = function () //{{{ +with (liberator) liberator.QuickMarks = function () //{{{ { //////////////////////////////////////////////////////////////////////////////// ////////////////////// PRIVATE SECTION ///////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ - var qmarks = liberator.storage.newMap("quickmarks", true); + var qmarks = storage.newMap("quickmarks", true); /////////////////////////////////////////////////////////////////////////////}}} ////////////////////// MAPPINGS //////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ - var modes = liberator.config.browserModes || [liberator.modes.NORMAL]; + var myModes = config.browserModes || [modes.NORMAL]; - liberator.mappings.add(modes, + mappings.add(myModes, ["go"], "Jump to a QuickMark", - function (arg) { liberator.quickmarks.jumpTo(arg, liberator.CURRENT_TAB); }, - { flags: liberator.Mappings.flags.ARGUMENT }); + function (arg) { quickmarks.jumpTo(arg, CURRENT_TAB); }, + { flags: Mappings.flags.ARGUMENT }); - liberator.mappings.add(modes, + mappings.add(myModes, ["gn"], "Jump to a QuickMark in a new tab", function (arg) { - liberator.quickmarks.jumpTo(arg, - /\bquickmark\b/.test(liberator.options["activate"]) ? - liberator.NEW_TAB : liberator.NEW_BACKGROUND_TAB); + quickmarks.jumpTo(arg, + /\bquickmark\b/.test(options["activate"]) ? + NEW_TAB : NEW_BACKGROUND_TAB); }, - { flags: liberator.Mappings.flags.ARGUMENT }); + { flags: Mappings.flags.ARGUMENT }); - liberator.mappings.add(modes, + mappings.add(myModes, ["M"], "Add new QuickMark for current URL", function (arg) { if (/[^a-zA-Z0-9]/.test(arg)) { - liberator.beep(); + beep(); return; } - liberator.quickmarks.add(arg, liberator.buffer.URL); + quickmarks.add(arg, buffer.URL); }, - { flags: liberator.Mappings.flags.ARGUMENT }); + { flags: Mappings.flags.ARGUMENT }); /////////////////////////////////////////////////////////////////////////////}}} ////////////////////// COMMANDS //////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ - liberator.commands.add(["delqm[arks]"], + commands.add(["delqm[arks]"], "Delete the specified QuickMarks", function (args, special) { // TODO: finish arg parsing - we really need a proper way to do this. :) if (!special && !args) { - liberator.echoerr("E471: Argument required"); + echoerr("E471: Argument required"); return; } if (special && args) { - liberator.echoerr("E474: Invalid argument"); + echoerr("E474: Invalid argument"); return; } if (special) - liberator.quickmarks.removeAll(); + quickmarks.removeAll(); else - liberator.quickmarks.remove(args); + quickmarks.remove(args); }, { bang: true }); - liberator.commands.add(["qma[rk]"], + commands.add(["qma[rk]"], "Mark a URL with a letter for quick access", function (args) { var matches = args.string.match(/^([a-zA-Z0-9])(?:\s+(.+))?$/); if (!matches) - liberator.echoerr("E488: Trailing characters"); + echoerr("E488: Trailing characters"); else if (!matches[2]) - liberator.quickmarks.add(matches[1], liberator.buffer.URL); + quickmarks.add(matches[1], buffer.URL); else - liberator.quickmarks.add(matches[1], matches[2]); + quickmarks.add(matches[1], matches[2]); }, { argCount: "+" }); - liberator.commands.add(["qmarks"], + commands.add(["qmarks"], "Show all QuickMarks", function (args) { // ignore invalid qmark characters unless there are no valid qmark chars if (args && !/[a-zA-Z0-9]/.test(args)) { - liberator.echoerr("E283: No QuickMarks matching \"" + args + "\""); + echoerr("E283: No QuickMarks matching \"" + args + "\""); return; } var filter = args.replace(/[^a-zA-Z0-9]/g, ""); - liberator.quickmarks.list(filter); + quickmarks.list(filter); }); /////////////////////////////////////////////////////////////////////////////}}} @@ -957,9 +957,9 @@ liberator.QuickMarks = function () //{{{ var url = qmarks.get(qmark); if (url) - liberator.open(url, where); + open(url, where); else - liberator.echoerr("E20: QuickMark not set"); + echoerr("E20: QuickMark not set"); }, list: function (filter) @@ -974,7 +974,7 @@ liberator.QuickMarks = function () //{{{ if (marks.length == 0) { - liberator.echoerr("No QuickMarks set"); + echoerr("No QuickMarks set"); return; } @@ -983,14 +983,14 @@ liberator.QuickMarks = function () //{{{ marks = marks.filter(function (qmark) filter.indexOf(qmark) >= 0); if (marks.length == 0) { - liberator.echoerr("E283: No QuickMarks matching \"" + filter + "\""); + echoerr("E283: No QuickMarks matching \"" + filter + "\""); return; } } let items = ({title: mark, url: qmarks.get(mark)} for each (mark in marks)); - let list = liberator.template.bookmarks("QuickMark", items); - liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); + let list = template.bookmarks("QuickMark", items); + commandline.echo(list, commandline.HL_NORMAL, commandline.FORCE_MULTILINE); } }; //}}} diff --git a/content/buffer.js b/content/buffer.js index 643f85a7..128bca86 100644 --- a/content/buffer.js +++ b/content/buffer.js @@ -28,7 +28,7 @@ the terms of any one of the MPL, the GPL or the LGPL. Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); -liberator.Buffer = function () //{{{ +with (liberator) liberator.Buffer = function () //{{{ { //////////////////////////////////////////////////////////////////////////////// ////////////////////// PRIVATE SECTION ///////////////////////////////////////// @@ -44,14 +44,14 @@ liberator.Buffer = function () //{{{ ]; const highlightDocs = "chrome://liberator/content/buffer.xhtml,chrome://browser/content/browser.xul"; - var highlight = liberator.storage.newMap("highlight", false); + var highlight = storage.newMap("highlight", false); var zoomLevels = [ 1, 10, 25, 50, 75, 90, 100, 120, 150, 200, 300, 500, 1000, 2000 ]; + const util = liberator.util; const arrayIter = liberator.util.arrayIter; - const util = liberator.util; function Styles(name, store, serial) { /* Can't reference liberator or Components inside Styles -- @@ -269,10 +269,10 @@ liberator.Buffer = function () //{{{ get sites() util.uniq(util.flatten([v.sites for ([k, v] in this.userSheets)])), }; - let styles = liberator.storage.newObject("styles", Styles, false); + let styles = storage.newObject("styles", Styles, false); /* FIXME: This doesn't belong here. */ - let mainWindowID = liberator.config.mainWindowID || "main-window"; + let mainWindowID = config.mainWindowID || "main-window"; let fontSize = document.defaultView.getComputedStyle(document.getElementById(mainWindowID), null) .getPropertyValue("font-size"); @@ -284,7 +284,7 @@ liberator.Buffer = function () //{{{ { if (value < 1 || value > 2000) { - liberator.echoerr("Zoom value out of range (1-2000%)"); + echoerr("Zoom value out of range (1-2000%)"); return; } @@ -293,13 +293,13 @@ liberator.Buffer = function () //{{{ else getBrowser().markupDocumentViewer.textZoom = value / 100.0; - liberator.echo((fullZoom ? "Full zoom: " : "Text zoom: ") + value + "%"); + echo((fullZoom ? "Full zoom: " : "Text zoom: ") + value + "%"); // TODO: shouldn't this just recalculate hint coords, rather than // unsuccessfully attempt to reshow hints? i.e. isn't it just relying // on the recalculation side effect? -- djk // NOTE: we could really do with a zoom event... - // liberator.hints.reshowHints(); + // hints.reshowHints(); } function bumpZoomLevel(steps, fullZoom) @@ -334,7 +334,7 @@ liberator.Buffer = function () //{{{ } if (index < 0 || index >= zoomLevels.length) { - liberator.beep(); + beep(); return; } setZoom(zoomLevels[index], fullZoom); @@ -344,7 +344,7 @@ liberator.Buffer = function () //{{{ { // NOTE: it's possible to have scrollY > scrollMaxY - FF bug? if (direction > 0 && win.scrollY >= win.scrollMaxY || direction < 0 && win.scrollY == 0) - liberator.beep(); + beep(); } function findScrollableWindow() @@ -395,9 +395,9 @@ liberator.Buffer = function () //{{{ /////////////////////////////////////////////////////////////////////////////{{{ // override this stupid pref, because otherwise zoom is lost after switching tabs - liberator.options.setPref("browser.zoom.siteSpecific", false); + options.setPref("browser.zoom.siteSpecific", false); - liberator.options.add(["fullscreen", "fs"], + options.add(["fullscreen", "fs"], "Show the current window fullscreen", "boolean", false, { @@ -409,23 +409,23 @@ liberator.Buffer = function () //{{{ getter: function () window.fullScreen }); - liberator.options.add(["nextpattern"], + options.add(["nextpattern"], "Patterns to use when guessing the 'next' page in a document sequence", "stringlist", "\\bnext\\b,^>$,^(>>|»)$,^(>|»),(>|»)$,\\bmore\\b"); - liberator.options.add(["previouspattern"], + options.add(["previouspattern"], "Patterns to use when guessing the 'previous' page in a document sequence", "stringlist", "\\bprev|previous\\b,^<$,^(<<|«)$,^(<|«),(<|«)$"); - liberator.options.add(["pageinfo", "pa"], "Desired info on :pa[geinfo]", "charlist", "gfm", + options.add(["pageinfo", "pa"], "Desired info on :pa[geinfo]", "charlist", "gfm", { completer: function (filter) [[k, v[1]] for ([k, v] in Iterator(pageInfo))] }); - liberator.options.add(["scroll", "scr"], + options.add(["scroll", "scr"], "Number of lines to scroll with and commands", "number", 0, { validator: function (value) value >= 0 }); - liberator.options.add(["showstatuslinks", "ssli"], + options.add(["showstatuslinks", "ssli"], "Show the destination of the link under the cursor in the status bar", "number", 1, { @@ -437,7 +437,7 @@ liberator.Buffer = function () //{{{ validator: function (value) value >= 0 && value <= 2 }); - liberator.options.add(["usermode", "um"], + options.add(["usermode", "um"], "Show current website with a minimal style sheet to make it easily accessible", "boolean", false, { @@ -465,142 +465,142 @@ liberator.Buffer = function () //{{{ ////////////////////// MAPPINGS //////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ - var modes = liberator.config.browserModes || [liberator.modes.NORMAL]; + var myModes = config.browserModes || [modes.NORMAL]; - liberator.mappings.add(modes, ["."], + mappings.add(myModes, ["."], "Repeat the last key event", function (count) { - if (liberator.mappings.repeat) + if (mappings.repeat) { - for (let i in liberator.util.rangeInterruptable(0, count || 1, 100)) - liberator.mappings.repeat(); + for (let i in util.rangeInterruptable(0, count || 1, 100)) + mappings.repeat(); } }, - { flags: liberator.Mappings.flags.COUNT }); + { flags: Mappings.flags.COUNT }); - liberator.mappings.add(modes, ["i", ""], + mappings.add(myModes, ["i", ""], "Start caret mode", function () { // setting this option triggers an observer which takes care of the mode setting - liberator.options.setPref("accessibility.browsewithcaret", true); + options.setPref("accessibility.browsewithcaret", true); }); - liberator.mappings.add(modes, [""], + mappings.add(myModes, [""], "Stop loading", function () { BrowserStop(); }); // scrolling - liberator.mappings.add(modes, ["j", "", ""], + mappings.add(myModes, ["j", "", ""], "Scroll document down", - function (count) { liberator.buffer.scrollLines(count > 1 ? count : 1); }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { buffer.scrollLines(count > 1 ? count : 1); }, + { flags: Mappings.flags.COUNT }); - liberator.mappings.add(modes, ["k", "", ""], + mappings.add(myModes, ["k", "", ""], "Scroll document up", - function (count) { liberator.buffer.scrollLines(-(count > 1 ? count : 1)); }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { buffer.scrollLines(-(count > 1 ? count : 1)); }, + { flags: Mappings.flags.COUNT }); - liberator.mappings.add(modes, liberator.has("mail") ? ["h"] : ["h", ""], + mappings.add(myModes, liberator.has("mail") ? ["h"] : ["h", ""], "Scroll document to the left", - function (count) { liberator.buffer.scrollColumns(-(count > 1 ? count : 1)); }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { buffer.scrollColumns(-(count > 1 ? count : 1)); }, + { flags: Mappings.flags.COUNT }); - liberator.mappings.add(modes, liberator.has("mail") ? ["l"] : ["l", ""], + mappings.add(myModes, liberator.has("mail") ? ["l"] : ["l", ""], "Scroll document to the right", - function (count) { liberator.buffer.scrollColumns(count > 1 ? count : 1); }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { buffer.scrollColumns(count > 1 ? count : 1); }, + { flags: Mappings.flags.COUNT }); - liberator.mappings.add(modes, ["0", "^"], + mappings.add(myModes, ["0", "^"], "Scroll to the absolute left of the document", - function () { liberator.buffer.scrollStart(); }); + function () { buffer.scrollStart(); }); - liberator.mappings.add(modes, ["$"], + mappings.add(myModes, ["$"], "Scroll to the absolute right of the document", - function () { liberator.buffer.scrollEnd(); }); + function () { buffer.scrollEnd(); }); - liberator.mappings.add(modes, ["gg", ""], + mappings.add(myModes, ["gg", ""], "Go to the top of the document", - function (count) { liberator.buffer.scrollToPercentile(count > 0 ? count : 0); }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { buffer.scrollToPercentile(count > 0 ? count : 0); }, + { flags: Mappings.flags.COUNT }); - liberator.mappings.add(modes, ["G", ""], + mappings.add(myModes, ["G", ""], "Go to the end of the document", - function (count) { liberator.buffer.scrollToPercentile(count >= 0 ? count : 100); }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { buffer.scrollToPercentile(count >= 0 ? count : 100); }, + { flags: Mappings.flags.COUNT }); - liberator.mappings.add(modes, ["%"], + mappings.add(myModes, ["%"], "Scroll to {count} percent of the document", function (count) { if (count > 0 && count <= 100) - liberator.buffer.scrollToPercentile(count); + buffer.scrollToPercentile(count); else - liberator.beep(); + beep(); }, - { flags: liberator.Mappings.flags.COUNT }); + { flags: Mappings.flags.COUNT }); - liberator.mappings.add(modes, [""], + mappings.add(myModes, [""], "Scroll window downwards in the buffer", - function (count) { liberator.buffer.scrollByScrollSize(count, 1); }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { buffer.scrollByScrollSize(count, 1); }, + { flags: Mappings.flags.COUNT }); - liberator.mappings.add(modes, [""], + mappings.add(myModes, [""], "Scroll window upwards in the buffer", - function (count) { liberator.buffer.scrollByScrollSize(count, -1); }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { buffer.scrollByScrollSize(count, -1); }, + { flags: Mappings.flags.COUNT }); - liberator.mappings.add(modes, ["", "", ""], + mappings.add(myModes, ["", "", ""], "Scroll up a full page", - function (count) { liberator.buffer.scrollPages(-(count > 1 ? count : 1)); }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { buffer.scrollPages(-(count > 1 ? count : 1)); }, + { flags: Mappings.flags.COUNT }); - liberator.mappings.add(modes, ["", "", ""], + mappings.add(myModes, ["", "", ""], "Scroll down a full page", - function (count) { liberator.buffer.scrollPages(count > 1 ? count : 1); }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { buffer.scrollPages(count > 1 ? count : 1); }, + { flags: Mappings.flags.COUNT }); - liberator.mappings.add(modes, ["]f"], + mappings.add(myModes, ["]f"], "Focus next frame", - function (count) { liberator.buffer.shiftFrameFocus(count > 1 ? count : 1, true); }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { buffer.shiftFrameFocus(count > 1 ? count : 1, true); }, + { flags: Mappings.flags.COUNT }); - liberator.mappings.add(modes, ["[f"], + mappings.add(myModes, ["[f"], "Focus previous frame", - function (count) { liberator.buffer.shiftFrameFocus(count > 1 ? count : 1, false); }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { buffer.shiftFrameFocus(count > 1 ? count : 1, false); }, + { flags: Mappings.flags.COUNT }); - liberator.mappings.add(modes, ["]]"], + mappings.add(myModes, ["]]"], "Follow the link labeled 'next' or '>' if it exists", - function (count) { liberator.buffer.followDocumentRelationship("next"); }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { buffer.followDocumentRelationship("next"); }, + { flags: Mappings.flags.COUNT }); - liberator.mappings.add(modes, ["[["], + mappings.add(myModes, ["[["], "Follow the link labeled 'prev', 'previous' or '<' if it exists", - function (count) { liberator.buffer.followDocumentRelationship("previous"); }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { buffer.followDocumentRelationship("previous"); }, + { flags: Mappings.flags.COUNT }); - liberator.mappings.add(modes, ["gf"], + mappings.add(myModes, ["gf"], "View source", - function () { liberator.buffer.viewSource(null, false); }); + function () { buffer.viewSource(null, false); }); - liberator.mappings.add(modes, ["gF"], + mappings.add(myModes, ["gF"], "View source with an external editor", - function () { liberator.buffer.viewSource(null, true); }); + function () { buffer.viewSource(null, true); }); - liberator.mappings.add(modes, ["gi"], + mappings.add(myModes, ["gi"], "Focus last used input field", function (count) { - if (count < 1 && liberator.buffer.lastInputField) + if (count < 1 && buffer.lastInputField) { - liberator.buffer.lastInputField.focus(); + buffer.lastInputField.focus(); } else { var elements = []; - var matches = liberator.buffer.evaluateXPath( + var matches = buffer.evaluateXPath( // TODO: type="file" "//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)]" @@ -625,184 +625,184 @@ liberator.Buffer = function () //{{{ } else { - liberator.beep(); + beep(); } } }, - { flags: liberator.Mappings.flags.COUNT }); + { flags: Mappings.flags.COUNT }); - liberator.mappings.add(modes, ["gP"], + mappings.add(myModes, ["gP"], "Open (put) a URL based on the current clipboard contents in a new buffer", function () { - liberator.open(liberator.util.readFromClipboard(), - /\bpaste\b/.test(liberator.options["activate"]) ? - liberator.NEW_BACKGROUND_TAB : liberator.NEW_TAB); + open(util.readFromClipboard(), + /\bpaste\b/.test(options["activate"]) ? + NEW_BACKGROUND_TAB : NEW_TAB); }); - liberator.mappings.add(modes, ["p", ""], + mappings.add(myModes, ["p", ""], "Open (put) a URL based on the current clipboard contents in the current buffer", - function () { liberator.open(liberator.util.readFromClipboard()); }); + function () { open(util.readFromClipboard()); }); - liberator.mappings.add(modes, ["P"], + mappings.add(myModes, ["P"], "Open (put) a URL based on the current clipboard contents in a new buffer", function () { - liberator.open(liberator.util.readFromClipboard(), - /\bpaste\b/.test(liberator.options["activate"]) ? - liberator.NEW_TAB : liberator.NEW_BACKGROUND_TAB); + open(util.readFromClipboard(), + /\bpaste\b/.test(options["activate"]) ? + NEW_TAB : NEW_BACKGROUND_TAB); }); // reloading - liberator.mappings.add(modes, ["r"], + mappings.add(myModes, ["r"], "Reload current page", - function () { liberator.tabs.reload(getBrowser().mCurrentTab, false); }); + function () { tabs.reload(getBrowser().mCurrentTab, false); }); - liberator.mappings.add(modes, ["R"], + mappings.add(myModes, ["R"], "Reload while skipping the cache", - function () { liberator.tabs.reload(getBrowser().mCurrentTab, true); }); + function () { tabs.reload(getBrowser().mCurrentTab, true); }); // yanking - liberator.mappings.add(modes, ["Y"], + mappings.add(myModes, ["Y"], "Copy selected text or current word", function () { - var sel = liberator.buffer.getCurrentWord(); + var sel = buffer.getCurrentWord(); if (sel) - liberator.util.copyToClipboard(sel, true); + util.copyToClipboard(sel, true); else - liberator.beep(); + beep(); }); // zooming - liberator.mappings.add(modes, ["zi", "+"], + mappings.add(myModes, ["zi", "+"], "Enlarge text zoom of current web page", - function (count) { liberator.buffer.zoomIn(count > 1 ? count : 1, false); }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { buffer.zoomIn(count > 1 ? count : 1, false); }, + { flags: Mappings.flags.COUNT }); - liberator.mappings.add(modes, ["zm"], + mappings.add(myModes, ["zm"], "Enlarge text zoom of current web page by a larger amount", - function (count) { liberator.buffer.zoomIn((count > 1 ? count : 1) * 3, false); }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { buffer.zoomIn((count > 1 ? count : 1) * 3, false); }, + { flags: Mappings.flags.COUNT }); - liberator.mappings.add(modes, ["zo", "-"], + mappings.add(myModes, ["zo", "-"], "Reduce text zoom of current web page", - function (count) { liberator.buffer.zoomOut(count > 1 ? count : 1, false); }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { buffer.zoomOut(count > 1 ? count : 1, false); }, + { flags: Mappings.flags.COUNT }); - liberator.mappings.add(modes, ["zr"], + mappings.add(myModes, ["zr"], "Reduce text zoom of current web page by a larger amount", - function (count) { liberator.buffer.zoomOut((count > 1 ? count : 1) * 3, false); }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { buffer.zoomOut((count > 1 ? count : 1) * 3, false); }, + { flags: Mappings.flags.COUNT }); - liberator.mappings.add(modes, ["zz"], + mappings.add(myModes, ["zz"], "Set text zoom value of current web page", - function (count) { liberator.buffer.textZoom = count > 1 ? count : 100; }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { buffer.textZoom = count > 1 ? count : 100; }, + { flags: Mappings.flags.COUNT }); - liberator.mappings.add(modes, ["zI"], + mappings.add(myModes, ["zI"], "Enlarge full zoom of current web page", - function (count) { liberator.buffer.zoomIn(count > 1 ? count : 1, true); }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { buffer.zoomIn(count > 1 ? count : 1, true); }, + { flags: Mappings.flags.COUNT }); - liberator.mappings.add(modes, ["zM"], + mappings.add(myModes, ["zM"], "Enlarge full zoom of current web page by a larger amount", - function (count) { liberator.buffer.zoomIn((count > 1 ? count : 1) * 3, true); }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { buffer.zoomIn((count > 1 ? count : 1) * 3, true); }, + { flags: Mappings.flags.COUNT }); - liberator.mappings.add(modes, ["zO"], + mappings.add(myModes, ["zO"], "Reduce full zoom of current web page", - function (count) { liberator.buffer.zoomOut(count > 1 ? count : 1, true); }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { buffer.zoomOut(count > 1 ? count : 1, true); }, + { flags: Mappings.flags.COUNT }); - liberator.mappings.add(modes, ["zR"], + mappings.add(myModes, ["zR"], "Reduce full zoom of current web page by a larger amount", - function (count) { liberator.buffer.zoomOut((count > 1 ? count : 1) * 3, true); }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { buffer.zoomOut((count > 1 ? count : 1) * 3, true); }, + { flags: Mappings.flags.COUNT }); - liberator.mappings.add(modes, ["zZ"], + mappings.add(myModes, ["zZ"], "Set full zoom value of current web page", - function (count) { liberator.buffer.fullZoom = count > 1 ? count : 100; }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { buffer.fullZoom = count > 1 ? count : 100; }, + { flags: Mappings.flags.COUNT }); // page info - liberator.mappings.add(modes, [""], + mappings.add(myModes, [""], "Print the current file name", - function (count) { liberator.buffer.showPageInfo(false); }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { buffer.showPageInfo(false); }, + { flags: Mappings.flags.COUNT }); - liberator.mappings.add(modes, ["g"], + mappings.add(myModes, ["g"], "Print file information", - function () { liberator.buffer.showPageInfo(true); }); + function () { buffer.showPageInfo(true); }); /////////////////////////////////////////////////////////////////////////////}}} ////////////////////// COMMANDS //////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ - liberator.commands.add(["ha[rdcopy]"], + commands.add(["ha[rdcopy]"], "Print current document", function (args, special) { - var aps = liberator.options.getPref("print.always_print_silent"); - var spp = liberator.options.getPref("print.show_print_progress"); + var aps = options.getPref("print.always_print_silent"); + var spp = options.getPref("print.show_print_progress"); - liberator.echo("Sending to printer..."); - liberator.options.setPref("print.always_print_silent", special); - liberator.options.setPref("print.show_print_progress", !special); + echo("Sending to printer..."); + options.setPref("print.always_print_silent", special); + options.setPref("print.show_print_progress", !special); getBrowser().contentWindow.print(); - liberator.options.setPref("print.always_print_silent", aps); - liberator.options.setPref("print.show_print_progress", spp); - liberator.echo("Print job sent."); + options.setPref("print.always_print_silent", aps); + options.setPref("print.show_print_progress", spp); + echo("Print job sent."); }, { argCount: "0", bang: true }); - liberator.commands.add(["pa[geinfo]"], + commands.add(["pa[geinfo]"], "Show various page information", - function () { liberator.buffer.showPageInfo(true); }, + function () { buffer.showPageInfo(true); }, { argCount: "0" }); - liberator.commands.add(["pagest[yle]"], + commands.add(["pagest[yle]"], "Select the author style sheet to apply", function (args) { - var titles = liberator.buffer.alternateStyleSheets.map(function (stylesheet) stylesheet.title); + var titles = buffer.alternateStyleSheets.map(function (stylesheet) stylesheet.title); if (args && titles.indexOf(args) == -1) { - liberator.echoerr("E475: Invalid argument: " + args); + echoerr("E475: Invalid argument: " + args); return; } - if (liberator.options["usermode"]) - liberator.options["usermode"] = false; + if (options["usermode"]) + options["usermode"] = false; stylesheetSwitchAll(window.content, args); }, - { completer: function (filter) liberator.completion.stylesheet(filter) }); + { completer: function (filter) completion.stylesheet(filter) }); - liberator.commands.add(["re[load]"], + commands.add(["re[load]"], "Reload current page", - function (args, special) { liberator.tabs.reload(getBrowser().mCurrentTab, special); }, + function (args, special) { tabs.reload(getBrowser().mCurrentTab, special); }, { bang: true, argCount: "0" }); - liberator.commands.add(["sav[eas]", "w[rite]"], + commands.add(["sav[eas]", "w[rite]"], "Save current document to disk", function (args, special) { let doc = window.content.document; - let file = liberator.io.getFile(args || ""); + let file = io.getFile(args || ""); if (args && file.exists() && !special) - return liberator.echoerr("E13: File exists (add ! to override)"); + return echoerr("E13: File exists (add ! to override)"); - liberator.options.setPref("browser.download.lastDir", liberator.io.getCurrentDirectory()); + options.setPref("browser.download.lastDir", io.getCurrentDirectory()); try { var contentDisposition = window.content @@ -819,15 +819,15 @@ liberator.Buffer = function () //{{{ }, { bang: true, - completer: function (filter) liberator.completion.file(filter) + completer: function (filter) completion.file(filter) }); - liberator.commands.add(["st[op]"], + commands.add(["st[op]"], "Stop loading", function () { BrowserStop(); }, { argCount: "0" }); - liberator.commands.add(["sty[le]"], + commands.add(["sty[le]"], "Add or list user styles", function (args, special) { @@ -839,18 +839,18 @@ liberator.Buffer = function () //{{{ { let list = Array.concat([i for (i in styles.userNames)], [i for (i in styles.userSheets) if (!i[1].ref.length)]); - let str = liberator.template.tabular(["", "Filter", "CSS"], + let str = template.tabular(["", "Filter", "CSS"], ["padding: 0 1em 0 1ex; vertical-align: top", "padding: 0 1em 0 0; vertical-align: top"], ([k, v[1].join(","), v[2]] for ([i, [k, v]] in Iterator(list)) if ((!filter || v[1].indexOf(filter) >= 0) && (!name || v[0] == name)))); - liberator.commandline.echo(str, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); + commandline.echo(str, commandline.HL_NORMAL, commandline.FORCE_MULTILINE); } else { let err = styles.addSheet(name, filter, css, false, special); if (err) - liberator.echoerr(err); + echoerr(err); } }, { @@ -863,34 +863,34 @@ liberator.Buffer = function () //{{{ } catch (e) {} comp = compl.concat([[s, ""] for each (s in styles.sites)]) - return [0, liberator.completion.filter(compl, filter)]; + return [0, completion.filter(compl, filter)]; }, argCount: 1, bang: true, hereDoc: true, literal: true, - options: [[["-name", "-n"], liberator.commands.OPTION_STRING]] + options: [[["-name", "-n"], commands.OPTION_STRING]] }); - liberator.commands.add(["dels[tyle]"], + commands.add(["dels[tyle]"], "Remove a user stylesheet", function (args) { styles.removeSheet(args["-name"], args.arguments[0], args.literalArg, args["-index"], false); }, { argCount: 1, - completer: function (filter) [0, liberator.completion.filter( + completer: function (filter) [0, completion.filter( [[i, <>{s.sites.join(",")}: {s.css.replace("\n", "\\n")}] for ([i, s] in styles.userSheets) ] .concat([[s, ""] for each (s in styles.sites)]) , filter)], literal: true, - options: [[["-index", "-i"], liberator.commands.OPTION_INT], - [["-name", "-n"], liberator.commands.OPTION_STRING]], + options: [[["-index", "-i"], commands.OPTION_INT], + [["-name", "-n"], commands.OPTION_STRING]], }); - liberator.commands.add(["hi[ghlight]"], + commands.add(["hi[ghlight]"], "Set the style of certain display elements", function (args, special) { @@ -898,19 +898,19 @@ liberator.Buffer = function () //{{{ let css = args.literalArg; if (!css && !(key && special)) { - let str = liberator.template.tabular(["Key", "CSS"], + let str = template.tabular(["Key", "CSS"], ["padding: 0 1em 0 0; vertical-align: top"], (h for (h in highlight) if (!key || h[0].indexOf(key) > -1))); - liberator.commandline.echo(str, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); + commandline.echo(str, commandline.HL_NORMAL, commandline.FORCE_MULTILINE); return; } - liberator.buffer.highlight(key, css, special); + buffer.highlight(key, css, special); }, { // TODO: add this as a standard highlight completion function? // I agree. It could (should) be much more sophisticated. --Kris completer: function (filter) [0, - liberator.completion.filter([[v instanceof Array ? v[0] : v, ""] for ([k, v] in Iterator(highlightClasses))], filter) + completion.filter([[v instanceof Array ? v[0] : v, ""] for ([k, v] in Iterator(highlightClasses))], filter) ], argCount: 1, bang: true, @@ -918,15 +918,15 @@ liberator.Buffer = function () //{{{ literal: true, }); - liberator.commands.add(["vie[wsource]"], + commands.add(["vie[wsource]"], "View source code of current document", - function (args, special) { liberator.buffer.viewSource(args.arguments[0], special); }, + function (args, special) { buffer.viewSource(args.arguments[0], special); }, { argCount: "1", bang: true }); - liberator.commands.add(["zo[om]"], + commands.add(["zo[om]"], "Set zoom value of current web page", function (args, special) { @@ -943,9 +943,9 @@ liberator.Buffer = function () //{{{ else if (/^[+-]\d+$/.test(args)) { if (special) - level = liberator.buffer.fullZoom + parseInt(args, 10); + level = buffer.fullZoom + parseInt(args, 10); else - level = liberator.buffer.textZoom + parseInt(args, 10); + level = buffer.textZoom + parseInt(args, 10); // relative args shouldn't take us out of range if (level < 1) @@ -955,14 +955,14 @@ liberator.Buffer = function () //{{{ } else { - liberator.echoerr("E488: Trailing characters"); + echoerr("E488: Trailing characters"); return; } if (special) - liberator.buffer.fullZoom = level; + buffer.fullZoom = level; else - liberator.buffer.textZoom = level; + buffer.textZoom = level; }, { bang: true }); @@ -1039,7 +1039,7 @@ liberator.Buffer = function () //{{{ nFeed++; var type = feedTypes[feed.type] || feedTypes["application/rss+xml"]; if (verbose) - yield [feed.title, liberator.template.highlightURL(feed.href, true) +  ({type})]; + yield [feed.title, template.highlightURL(feed.href, true) +  ({type})]; } } } @@ -1073,8 +1073,8 @@ liberator.Buffer = function () //{{{ var pageSize = []; // [0] bytes; [1] kbytes if (cacheEntryDescriptor) { - pageSize[0] = liberator.util.formatBytes(cacheEntryDescriptor.dataSize, 0, false); - pageSize[1] = liberator.util.formatBytes(cacheEntryDescriptor.dataSize, 2, true); + pageSize[0] = util.formatBytes(cacheEntryDescriptor.dataSize, 0, false); + pageSize[1] = util.formatBytes(cacheEntryDescriptor.dataSize, 2, true); if (pageSize[1] == pageSize[0]) pageSize.length = 1; // don't output "xx Bytes" twice } @@ -1094,11 +1094,11 @@ liberator.Buffer = function () //{{{ } yield ["Title", doc.title]; - yield ["URL", liberator.template.highlightURL(doc.location.toString(), true)]; + yield ["URL", template.highlightURL(doc.location.toString(), true)]; var ref = "referrer" in doc && doc.referrer; if (ref) - yield ["Referrer", liberator.template.highlightURL(ref, true)]; + yield ["Referrer", template.highlightURL(ref, true)]; if (pageSize[0]) yield ["File Size", pageSize[1] ? pageSize[1] + " (" + pageSize[0] + ")" @@ -1116,7 +1116,7 @@ liberator.Buffer = function () //{{{ // get meta tag data, sort and put into pageMeta[] var metaNodes = window.content.document.getElementsByTagName("meta"); - return Array.map(metaNodes, function (node) [(node.name || node.httpEquiv), liberator.template.highlightURL(node.content)]) + return Array.map(metaNodes, function (node) [(node.name || node.httpEquiv), template.highlightURL(node.content)]) .sort(function (a, b) String.localeCompare(a[0].toLowerCase(), b[0].toLowerCase())); }); @@ -1207,7 +1207,7 @@ liberator.Buffer = function () //{{{ class = highlightClasses.filter(function (i) i == class || i[0] == class)[0]; if (!class) { - liberator.echoerr("Unknown highlight keyword"); + echoerr("Unknown highlight keyword"); return; } if (!(class instanceof Array)) @@ -1228,7 +1228,7 @@ liberator.Buffer = function () //{{{ let error = styles.addSheet("hl-" + key, scope, css, true, force); if (error) - liberator.echoerr(error); + echoerr(error); else highlight.set(key, style); }, @@ -1292,7 +1292,7 @@ liberator.Buffer = function () //{{{ // argument "args" is something like: @id='myid' or @type='text' (don't forget the quotes around myid) getElement: function (args, index) { - return liberator.buffer.evaluateXPath("//*[" + (args || "") + "]").snapshotItem(index || 0); + return buffer.evaluateXPath("//*[" + (args || "") + "]").snapshotItem(index || 0); }, // more advanced than a simple elem.focus() as it also works for iframes @@ -1338,16 +1338,16 @@ liberator.Buffer = function () //{{{ switch (relationship) { case "next": - regexps = liberator.options["nextpattern"].split(","); + regexps = options["nextpattern"].split(","); revString = "previous"; break; case "previous": // TODO: accept prev\%[ious] - regexps = liberator.options["previouspattern"].split(","); + regexps = options["previouspattern"].split(","); revString = "next"; break; default: - liberator.echoerr("Bad document relationship: " + relationship); + echoerr("Bad document relationship: " + relationship); } relText = new RegExp(relationship, "i"); @@ -1358,7 +1358,7 @@ liberator.Buffer = function () //{{{ { if (relText.test(elems[i].rel) || revText.test(elems[i].rev)) { - liberator.open(elems[i].href); + open(elems[i].href); return true; } } @@ -1369,7 +1369,7 @@ liberator.Buffer = function () //{{{ { if (relText.test(elems[i].rel) || revText.test(elems[i].rev)) { - liberator.buffer.followLink(elems[i], liberator.CURRENT_TAB); + buffer.followLink(elems[i], CURRENT_TAB); return true; } } @@ -1381,7 +1381,7 @@ liberator.Buffer = function () //{{{ { if (patternText.test(elems[i].textContent)) { - liberator.buffer.followLink(elems[i], liberator.CURRENT_TAB); + buffer.followLink(elems[i], CURRENT_TAB); return true; } else @@ -1392,7 +1392,7 @@ liberator.Buffer = function () //{{{ { if (patternText.test(children[j].alt)) { - liberator.buffer.followLink(elems[i], liberator.CURRENT_TAB); + buffer.followLink(elems[i], CURRENT_TAB); return true; } } @@ -1423,7 +1423,7 @@ liberator.Buffer = function () //{{{ } if (!retVal) - liberator.beep(); + beep(); }, // artificially "clicks" a link in order to open it @@ -1450,18 +1450,18 @@ liberator.Buffer = function () //{{{ var ctrlKey = false, shiftKey = false; switch (where) { - case liberator.NEW_TAB: - case liberator.NEW_BACKGROUND_TAB: + case NEW_TAB: + case NEW_BACKGROUND_TAB: ctrlKey = true; - shiftKey = (where == liberator.NEW_BACKGROUND_TAB); + shiftKey = (where == NEW_BACKGROUND_TAB); break; - case liberator.NEW_WINDOW: + case NEW_WINDOW: shiftKey = true; break; - case liberator.CURRENT_TAB: + case CURRENT_TAB: break; default: - liberator.log("Invalid where argument for followLink()", 0); + log("Invalid where argument for followLink()", 0); } elem.focus(); @@ -1485,12 +1485,12 @@ liberator.Buffer = function () //{{{ { urlSecurityCheck(url, doc.nodePrincipal); // we always want to save that link relative to the current working directory - liberator.options.setPref("browser.download.lastDir", liberator.io.getCurrentDirectory()); + options.setPref("browser.download.lastDir", io.getCurrentDirectory()); saveURL(url, text, null, true, skipPrompt, makeURI(url, doc.characterSet)); } catch (e) { - liberator.echoerr(e); + echoerr(e); } }, @@ -1505,7 +1505,7 @@ liberator.Buffer = function () //{{{ const COL_WIDTH = 20; if (cols > 0 && win.scrollX >= win.scrollMaxX || cols < 0 && win.scrollX == 0) - liberator.beep(); + beep(); win.scrollBy(COL_WIDTH * cols, 0); }, @@ -1532,13 +1532,13 @@ liberator.Buffer = function () //{{{ scrollByScrollSize: function (count, direction) { if (count > 0) - liberator.options["scroll"] = count; + options["scroll"] = count; var win = findScrollableWindow(); checkScrollYBounds(win, direction); - if (liberator.options["scroll"] > 0) - this.scrollLines(liberator.options["scroll"] * direction); + if (options["scroll"] > 0) + this.scrollLines(options["scroll"] * direction); else // scroll half a page down in pixels win.scrollBy(0, win.innerHeight / 2 * direction); }, @@ -1604,7 +1604,7 @@ liberator.Buffer = function () //{{{ if (next > frames.length - 1) { if (current == frames.length - 1) - liberator.beep(); // still allow the frame indicator to be activated + beep(); // still allow the frame indicator to be activated next = frames.length - 1; } @@ -1619,7 +1619,7 @@ liberator.Buffer = function () //{{{ if (next < 0) { if (current == 0) - liberator.beep(); // still allow the frame indicator to be activated + beep(); // still allow the frame indicator to be activated next = 0; } @@ -1632,7 +1632,7 @@ liberator.Buffer = function () //{{{ // add the frame indicator var doc = frames[next].document; - var indicator = liberator.util.xmlToDom(
, doc); + var indicator = util.xmlToDom(
, doc); doc.body.appendChild(indicator); // remove the frame indicator @@ -1643,7 +1643,7 @@ liberator.Buffer = function () //{{{ // TODO: print more useful information, just like the DOM inspector showElementInfo: function (elem) { - liberator.echo(<>Element:
+ liberator.util.objectToString(elem), liberator.commandline.FORCE_MULTILINE); + echo(<>Element:
+ util.objectToString(elem), commandline.FORCE_MULTILINE); }, showPageInfo: function (verbose) @@ -1654,27 +1654,27 @@ liberator.Buffer = function () //{{{ let file = content.document.location.pathname.split("/").pop() || "[No Name]"; let title = content.document.title || "[No Title]"; - let info = liberator.template.map("gf", function (opt) - liberator.template.map(pageInfo[opt][0](), + let info = template.map("gf", function (opt) + template.map(pageInfo[opt][0](), function (val) val, ", "), ", "); - if (liberator.bookmarks.isBookmarked(this.URL)) + if (bookmarks.isBookmarked(this.URL)) info += ", bookmarked"; var pageInfoText = <>"{file}" [{info}] {title}; - liberator.echo(pageInfoText, liberator.commandline.FORCE_SINGLELINE); + echo(pageInfoText, commandline.FORCE_SINGLELINE); return; } - let option = liberator.options["pageinfo"]; - let list = liberator.template.map(option, function (option) + let option = options["pageinfo"]; + let list = template.map(option, function (option) { let opt = pageInfo[option]; if (opt) - return liberator.template.table(opt[1], opt[0](true)); + return template.table(opt[1], opt[0](true)); },
); - liberator.echo(list, liberator.commandline.FORCE_MULTILINE); + echo(list, commandline.FORCE_MULTILINE); }, viewSelectionSource: function () @@ -1700,27 +1700,27 @@ liberator.Buffer = function () //{{{ // url is optional viewSource: function (url, useExternalEditor) { - url = url || liberator.buffer.URL; + url = url || buffer.URL; if (useExternalEditor) { // TODO: make that a helper function // TODO: save return value in v:shell_error - var editor = liberator.options["editor"]; - var args = liberator.commands.parseArgs(editor, [], "*", true).arguments; + var editor = options["editor"]; + var args = commands.parseArgs(editor, [], "*", true).arguments; if (args.length < 1) { - liberator.echoerr("No editor specified"); + echoerr("No editor specified"); return; } var prog = args.shift(); args.push(url); - liberator.callFunctionInThread(null, liberator.io.run, [prog, args, true]); + callFunctionInThread(null, io.run, [prog, args, true]); } else { - liberator.open("view-source:" + url); + open("view-source:" + url); } }, @@ -1737,14 +1737,14 @@ liberator.Buffer = function () //{{{ //}}} }; //}}} -liberator.Marks = function () //{{{ +with (liberator) liberator.Marks = function () //{{{ { //////////////////////////////////////////////////////////////////////////////// ////////////////////// PRIVATE SECTION ///////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ - var localMarks = liberator.storage.newMap('local-marks', true); - var urlMarks = liberator.storage.newMap('url-marks', true); + var localMarks = storage.newMap('local-marks', true); + var urlMarks = storage.newMap('url-marks', true); var pendingJumps = []; var appContent = document.getElementById("appcontent"); @@ -1772,7 +1772,7 @@ liberator.Marks = function () //{{{ return name + ", " + mark.location + ", (" + Math.round(mark.position.x * 100) + "%, " + Math.round(mark.position.y * 100) + "%)" + - (('tab' in mark) ? ", tab: " + liberator.tabs.index(mark.tab) : ""); + (('tab' in mark) ? ", tab: " + tabs.index(mark.tab) : ""); } function removeLocalMark(mark) @@ -1785,7 +1785,7 @@ liberator.Marks = function () //{{{ { if (localmark[i].location == win.location.href) { - liberator.log("Deleting local mark: " + markToString(mark, localmark[i]), 5); + log("Deleting local mark: " + markToString(mark, localmark[i]), 5); localmark.splice(i, 1); if (localmark.length == 0) localMarks.remove(mark); @@ -1800,7 +1800,7 @@ liberator.Marks = function () //{{{ var urlmark = urlMarks.get(mark); if (urlmark) { - liberator.log("Deleting URL mark: " + markToString(mark, urlmark), 5); + log("Deleting URL mark: " + markToString(mark, urlmark), 5); urlMarks.remove(mark); } } @@ -1841,43 +1841,43 @@ liberator.Marks = function () //{{{ ////////////////////// MAPPINGS //////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ - var modes = liberator.config.browserModes || [liberator.modes.NORMAL]; + var myModes = config.browserModes || [modes.NORMAL]; - liberator.mappings.add(modes, + mappings.add(myModes, ["m"], "Set mark at the cursor position", function (arg) { if (/[^a-zA-Z]/.test(arg)) { - liberator.beep(); + beep(); return; } - liberator.marks.add(arg); + marks.add(arg); }, - { flags: liberator.Mappings.flags.ARGUMENT }); + { flags: Mappings.flags.ARGUMENT }); - liberator.mappings.add(modes, + mappings.add(myModes, ["'", "`"], "Jump to the mark in the current buffer", - function (arg) { liberator.marks.jumpTo(arg); }, - { flags: liberator.Mappings.flags.ARGUMENT }); + function (arg) { marks.jumpTo(arg); }, + { flags: Mappings.flags.ARGUMENT }); /////////////////////////////////////////////////////////////////////////////}}} ////////////////////// COMMANDS //////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ - liberator.commands.add(["delm[arks]"], + commands.add(["delm[arks]"], "Delete the specified marks", function (args, special) { if (!special && !args) { - liberator.echoerr("E471: Argument required"); + echoerr("E471: Argument required"); return; } if (special && args) { - liberator.echoerr("E474: Invalid argument"); + echoerr("E474: Invalid argument"); return; } var matches; @@ -1886,7 +1886,7 @@ liberator.Marks = function () //{{{ // NOTE: this currently differs from Vim's behavior which // deletes any valid marks in the arg list, up to the first // invalid arg, as well as giving the error message. - liberator.echoerr("E475: Invalid argument: " + matches[0]); + echoerr("E475: Invalid argument: " + matches[0]); return; } // check for illegal ranges - only allow a-z A-Z 0-9 @@ -1901,49 +1901,49 @@ liberator.Marks = function () //{{{ /[0-9]/.test(start) != /[0-9]/.test(end) || start > end) { - liberator.echoerr("E475: Invalid argument: " + args.match(matches[i] + ".*")[0]); + echoerr("E475: Invalid argument: " + args.match(matches[i] + ".*")[0]); return; } } } - liberator.marks.remove(args, special); + marks.remove(args, special); }, { bang: true }); - liberator.commands.add(["ma[rk]"], + commands.add(["ma[rk]"], "Mark current location within the web page", function (args) { var mark = args.arguments[0]; if (mark.length > 1) { - liberator.echoerr("E488: Trailing characters"); + echoerr("E488: Trailing characters"); return; } if (!/[a-zA-Z]/.test(mark)) { - liberator.echoerr("E191: Argument must be a letter or forward/backward quote"); + echoerr("E191: Argument must be a letter or forward/backward quote"); return; } - liberator.marks.add(mark); + marks.add(mark); }, { argCount: "1" }); - liberator.commands.add(["marks"], + commands.add(["marks"], "Show all location marks of current web page", function (args) { // ignore invalid mark characters unless there are no valid mark chars if (args && !/[a-zA-Z]/.test(args)) { - liberator.echoerr("E283: No marks matching \"" + args + "\""); + echoerr("E283: No marks matching \"" + args + "\""); return; } var filter = args.replace(/[^a-zA-Z]/g, ""); - liberator.marks.list(filter); + marks.list(filter); }); /////////////////////////////////////////////////////////////////////////////}}} @@ -1959,7 +1959,7 @@ liberator.Marks = function () //{{{ if (win.document.body.localName.toLowerCase() == "frameset") { - liberator.echoerr("Marks support for frameset pages not implemented yet"); + echoerr("Marks support for frameset pages not implemented yet"); return; } @@ -1969,8 +1969,8 @@ liberator.Marks = function () //{{{ if (isURLMark(mark)) { - urlMarks.set(mark, { location: win.location.href, position: position, tab: liberator.tabs.getTab() }); - liberator.log("Adding URL mark: " + markToString(mark, urlMarks.get(mark)), 5); + urlMarks.set(mark, { location: win.location.href, position: position, tab: tabs.getTab() }); + log("Adding URL mark: " + markToString(mark, urlMarks.get(mark)), 5); } else if (isLocalMark(mark)) { @@ -1980,7 +1980,7 @@ liberator.Marks = function () //{{{ localMarks.set(mark, []); let vals = { location: win.location.href, position: position }; localMarks.get(mark).push(vals); - liberator.log("Adding local mark: " + markToString(mark, vals), 5); + log("Adding local mark: " + markToString(mark, vals), 5); } }, @@ -2022,13 +2022,13 @@ liberator.Marks = function () //{{{ pendingJumps.push(slice); // NOTE: this obviously won't work on generated pages using // non-unique URLs :( - liberator.open(slice.location, liberator.NEW_TAB); + open(slice.location, NEW_TAB); return; } - var index = liberator.tabs.index(slice.tab); + var index = tabs.index(slice.tab); if (index != -1) { - liberator.tabs.select(index); + tabs.select(index); var win = slice.tab.linkedBrowser.contentWindow; if (win.location.href != slice.location) { @@ -2036,7 +2036,7 @@ liberator.Marks = function () //{{{ win.location.href = slice.location; return; } - liberator.log("Jumping to URL mark: " + markToString(mark, slice), 5); + log("Jumping to URL mark: " + markToString(mark, slice), 5); win.scrollTo(slice.position.x * win.scrollMaxX, slice.position.y * win.scrollMaxY); ok = true; } @@ -2051,7 +2051,7 @@ liberator.Marks = function () //{{{ { if (win.location.href == slice[i].location) { - liberator.log("Jumping to local mark: " + markToString(mark, slice[i]), 5); + log("Jumping to local mark: " + markToString(mark, slice[i]), 5); win.scrollTo(slice[i].position.x * win.scrollMaxX, slice[i].position.y * win.scrollMaxY); ok = true; } @@ -2059,7 +2059,7 @@ liberator.Marks = function () //{{{ } if (!ok) - liberator.echoerr("E20: Mark not set"); // FIXME: move up? + echoerr("E20: Mark not set"); // FIXME: move up? }, list: function (filter) @@ -2068,7 +2068,7 @@ liberator.Marks = function () //{{{ if (marks.length == 0) { - liberator.echoerr("No marks set"); + echoerr("No marks set"); return; } @@ -2077,19 +2077,19 @@ liberator.Marks = function () //{{{ marks = marks.filter(function (mark) filter.indexOf(mark[0]) >= 0); if (marks.length == 0) { - liberator.echoerr("E283: No marks matching \"" + filter + "\""); + echoerr("E283: No marks matching \"" + filter + "\""); return; } } - let list = liberator.template.tabular(["mark", "line", "col", "file"], + let list = template.tabular(["mark", "line", "col", "file"], ["", "text-align: right", "text-align: right", "color: green"], ([mark[0], Math.round(mark[1].position.x * 100) + "%", Math.round(mark[1].position.y * 100) + "%", mark[1].location] for each (mark in marks))); - liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); + commandline.echo(list, commandline.HL_NORMAL, commandline.FORCE_MULTILINE); } }; diff --git a/content/commands.js b/content/commands.js index 31a05a4c..9ec7e333 100644 --- a/content/commands.js +++ b/content/commands.js @@ -27,8 +27,8 @@ the terms of any one of the MPL, the GPL or the LGPL. }}} ***** END LICENSE BLOCK *****/ // Do NOT create instances of this class yourself, use the helper method -// liberator.commands.add() instead -liberator.Command = function (specs, description, action, extraInfo) //{{{ +// commands.add() instead +with (liberator) liberator.Command = function (specs, description, action, extraInfo) //{{{ { if (!specs || !action) return null; @@ -86,7 +86,7 @@ liberator.Command = function (specs, description, action, extraInfo) //{{{ this.replacementText = extraInfo.replacementText || null; }; -liberator.Command.prototype = { +with (liberator) liberator.Command.prototype = { execute: function (args, special, count, modifiers) { @@ -100,7 +100,7 @@ liberator.Command.prototype = { // we use our args parser instead of passing a string to the callback if (this.options.length > 0 || this.argCount) { - args = liberator.commands.parseArgs(args, this.options, this.argCount, false, this.literal); + args = commands.parseArgs(args, this.options, this.argCount, false, this.literal); if (args == null) return false; } @@ -109,7 +109,7 @@ liberator.Command.prototype = { let matches = args.match(/(.*)<<\s*(\S+)$/); if (matches && matches[2]) { - liberator.commandline.inputMultiline(new RegExp("^" + matches[2] + "$", "m"), + commandline.inputMultiline(new RegExp("^" + matches[2] + "$", "m"), function (args) self.action.call(self, matches[1] + "\n" + args, special, count, modifiers)); return; } @@ -151,7 +151,7 @@ liberator.Command.prototype = { }; //}}} -liberator.Commands = function () //{{{ +with (liberator) liberator.Commands = function () //{{{ { //////////////////////////////////////////////////////////////////////////////// ////////////////////// PRIVATE SECTION ///////////////////////////////////////// @@ -195,7 +195,7 @@ liberator.Commands = function () //{{{ return NaN; } - const ArgType = new liberator.util.Struct("description", "parse"); + const ArgType = new util.Struct("description", "parse"); const argTypes = [ null, ["no arg", function (arg) !arg], @@ -237,7 +237,7 @@ liberator.Commands = function () //{{{ add: function (names, description, action, extra) { - var command = new liberator.Command(names, description, action, extra); + var command = new Command(names, description, action, extra); if (!command) return false; @@ -246,7 +246,7 @@ liberator.Commands = function () //{{{ if (exCommands[i].name == command.name) { // never replace for now - liberator.log("Warning: :" + names[0] + " already exists, NOT replacing existing command.", 1); + log("Warning: :" + names[0] + " already exists, NOT replacing existing command.", 1); return false; } } @@ -261,7 +261,7 @@ liberator.Commands = function () //{{{ extra.isUserCommand = true; description = description || "User defined command"; - var command = new liberator.Command(names, description, action, extra); + var command = new Command(names, description, action, extra); // FIXME: shouldn't this be testing for an existing command by name? // Requiring uppercase user command names like Vim would be easier if (!command) @@ -479,7 +479,7 @@ liberator.Commands = function () //{{{ } var sub = str.substr(i); - //liberator.dump(i + ": " + sub + " - " + onlyArgumentsRemaining + "\n"); + //dump(i + ": " + sub + " - " + onlyArgumentsRemaining + "\n"); if ((!onlyArgumentsRemaining) && /^--(\s|$)/.test(sub)) { onlyArgumentsRemaining = true; @@ -536,14 +536,14 @@ liberator.Commands = function () //{{{ { if (!complete) { - liberator.echoerr("Invalid argument for option " + optname); + echoerr("Invalid argument for option " + optname); return null; } let compl = opt[3] || []; if (typeof compl == "function") compl = compl(); let filter = quoteArg(sub[optname.length + 1]) - return [i + optname.length + 1, liberator.completion.filter(compl.map(filter), filter(arg))]; + return [i + optname.length + 1, completion.filter(compl.map(filter), filter(arg))]; } if (!invalid) @@ -554,7 +554,7 @@ liberator.Commands = function () //{{{ arg = type.parse(arg); if (arg == null || arg == NaN) { - liberator.echoerr("Invalid argument for " + type.description + "option: " + optname); + echoerr("Invalid argument for " + type.description + "option: " + optname); return null; } } @@ -564,7 +564,7 @@ liberator.Commands = function () //{{{ { if (opt[2].call(this, arg) == false) { - liberator.echoerr("Invalid argument for option: " + optname); + echoerr("Invalid argument for option: " + optname); return null; } } @@ -589,12 +589,12 @@ liberator.Commands = function () //{{{ var [count, arg] = getNextArg(sub); if (count == -1) { - liberator.echoerr("Error parsing arguments: " + arg); + echoerr("Error parsing arguments: " + arg); return null; } else if (!onlyArgumentsRemaining && /^-/.test(arg)) { - liberator.echoerr("Invalid option: " + arg); + echoerr("Invalid option: " + arg); return null; } @@ -610,13 +610,13 @@ liberator.Commands = function () //{{{ // check for correct number of arguments if (args.arguments.length == 0 && (argCount == "1" || argCount == "+")) { - liberator.echoerr("E471: Argument required"); + echoerr("E471: Argument required"); return null; } else if (args.arguments.length == 1 && (argCount == "0") || args.arguments.length > 1 && (argCount == "0" || argCount == "1" || argCount == "?")) { - liberator.echoerr("E488: Trailing characters"); + echoerr("E488: Trailing characters"); return null; } @@ -705,7 +705,7 @@ liberator.Commands = function () //{{{ count: this.count && count }; - liberator.execute(liberator.commands.replaceTokens(this.replacementText, tokens)); + execute(commands.replaceTokens(this.replacementText, tokens)); } // TODO: Vim allows commands to be defined without {rep} if there are {attr}s @@ -717,7 +717,7 @@ liberator.Commands = function () //{{{ let cmd = args.arguments[0]; if (cmd != null && /\W/.test(cmd)) { - liberator.echoerr("E182: Invalid command name"); + echoerr("E182: Invalid command name"); return; } @@ -727,7 +727,7 @@ liberator.Commands = function () //{{{ let bangOpt = "-bang" in args; let countOpt = "-count" in args; - if (!liberator.commands.addUserCommand( + if (!commands.addUserCommand( [cmd], "User defined command", userCommand, @@ -740,7 +740,7 @@ liberator.Commands = function () //{{{ special) ) { - liberator.echoerr("E174: Command already exists: add ! to replace it"); + echoerr("E174: Command already exists: add ! to replace it"); } } else @@ -754,18 +754,18 @@ liberator.Commands = function () //{{{ if (cmds.length > 0) { - let str = liberator.template.tabular(["", "Name", "Args", "Range", "Definition"], ["padding-right: 2em;"], + let str = template.tabular(["", "Name", "Args", "Range", "Definition"], ["padding-right: 2em;"], ([cmd.bang ? "!" : " ", cmd.name, cmd.argCount, cmd.count ? "0c" : "", cmd.replacementText || "function () { ... }"] for each (cmd in cmds))); - liberator.commandline.echo(str, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); + commandline.echo(str, commandline.HL_NORMAL, commandline.FORCE_MULTILINE); } else { - liberator.echo("No user-defined commands found"); + echo("No user-defined commands found"); } } }, @@ -773,7 +773,7 @@ liberator.Commands = function () //{{{ literal: true, argCount: 1, bang: true, - completer: function (filter) liberator.completion.userCommand(filter), + completer: function (filter) completion.userCommand(filter), options: [ [["-nargs"], commandManager.OPTION_STRING, function (arg) /^[01*?+]$/.test(arg), ["0", "1", "*", "?", "+"]], [["-bang"], commandManager.OPTION_NOARG], @@ -785,7 +785,7 @@ liberator.Commands = function () //{{{ "Delete all user-defined commands", function () { - liberator.commands.getUserCommands().forEach(function (cmd) { liberator.commands.removeUserCommand(cmd.name); }); + commands.getUserCommands().forEach(function (cmd) { commands.removeUserCommand(cmd.name); }); }, { argCount: "0" }); @@ -794,22 +794,22 @@ liberator.Commands = function () //{{{ function (args) { var name = args.arguments[0]; - var cmdlist = liberator.commands.getUserCommands(); + var cmdlist = commands.getUserCommands(); for (let i = 0; i < cmdlist.length; i++) { if (cmdlist[i].name == name) { - liberator.commands.removeUserCommand(name); + commands.removeUserCommand(name); return; } } - liberator.echoerr("E184: No such user-defined command: " + name); + echoerr("E184: No such user-defined command: " + name); }, { argCount: "1", - completer: function (filter) liberator.completion.userCommand(filter) + completer: function (filter) completion.userCommand(filter) }); //}}} diff --git a/content/completion.js b/content/completion.js index 4a8f6dbf..5d5bb55b 100644 --- a/content/completion.js +++ b/content/completion.js @@ -26,7 +26,7 @@ the provisions above, a recipient may use your version of this file under the terms of any one of the MPL, the GPL or the LGPL. }}} ***** END LICENSE BLOCK *****/ -liberator.Completion = function () //{{{ +with (liberator) liberator.Completion = function () //{{{ { //////////////////////////////////////////////////////////////////////////////// ////////////////////// PRIVATE SECTION ///////////////////////////////////////// @@ -49,9 +49,9 @@ liberator.Completion = function () //{{{ var historyResult = null; var completionCache = []; - var historyTimer = new liberator.util.Timer(50, 100, function () { + var historyTimer = new util.Timer(50, 100, function () { let comp = []; - for (let i in liberator.util.range(0, historyResult.matchCount)) + for (let i in util.range(0, historyResult.matchCount)) comp.push([historyResult.getValueAt(i), historyResult.getCommentAt(i), historyResult.getImageAt(i)]); @@ -59,7 +59,7 @@ liberator.Completion = function () //{{{ //let foo = ["", "IGNORED", "FAILURE", "NOMATCH", "SUCCESS", "NOMATCH_ONGOING", "SUCCESS_ONGOING"]; historyCache = comp; - liberator.commandline.setCompletions(completionCache.concat(historyCache)); + commandline.setCompletions(completionCache.concat(historyCache)); }); function Javascript() @@ -153,7 +153,7 @@ liberator.Completion = function () //{{{ obj = obj.wrappedJSObject; for (let [k, v] in this.iter(obj)) - compl.push([k, liberator.template.highlight(v, true)]); + compl.push([k, template.highlight(v, true)]); } return compl; } @@ -161,9 +161,9 @@ liberator.Completion = function () //{{{ this.filter = function filter(compl, key, last, offset) { if (last != undefined) // Escaping the key (without adding quotes), so it matches the escaped completions. - key = liberator.util.escapeString(key.substr(offset), ""); + key = util.escapeString(key.substr(offset), ""); - liberator.completion.filterString = key; + completion.filterString = key; let res = buildLongestStartingSubstring(compl, key); if (res.length == 0) { @@ -176,7 +176,7 @@ liberator.Completion = function () //{{{ if (last != undefined) // We're looking for a quoted string, so, strip whatever prefix we have and quote the rest { - res.forEach(function (a) a[0] = liberator.util.escapeString(a[0].substr(offset), last)); + res.forEach(function (a) a[0] = util.escapeString(a[0].substr(offset), last)); } else // We're not looking for a quoted string, so filter out anything that's not a valid identifier { @@ -190,8 +190,8 @@ liberator.Completion = function () //{{{ { try { - // liberator.dump("eval(" + liberator.util.escapeString(arg) + ")\n"); - return liberator.eval(arg); + // dump("eval(" + util.escapeString(arg) + ")\n"); + return eval(arg); } catch (e) { @@ -226,7 +226,7 @@ liberator.Completion = function () //{{{ if (top[CHAR] != arg) throw new Error("Invalid JS"); if (i == str.length - 1) - liberator.completion.parenMatch = top[OFFSET]; + completion.parenMatch = top[OFFSET]; // The closing character of this stack frame will have pushed a new // statement, leaving us with an empty statement. This doesn't matter, // now, as we simply throw away the frame when we pop it, but it may later. @@ -339,7 +339,7 @@ liberator.Completion = function () //{{{ } catch (e) { - liberator.dump(liberator.util.escapeString(string) + ": " + e + "\n" + e.stack); + dump(util.escapeString(string) + ": " + e + "\n" + e.stack); lastIdx = 0; return [0, []]; } @@ -490,7 +490,7 @@ liberator.Completion = function () //{{{ let idx; while ((idx = str.indexOf(filter, start)) > -1) { - for (let end in liberator.util.range(idx + length, str.length + 1)) + for (let end in util.range(idx + length, str.length + 1)) substrings.push(str.substring(idx, end)); start = idx + 1; } @@ -500,7 +500,7 @@ liberator.Completion = function () //{{{ // list = [ [['com1', 'com2'], 'text'], [['com3', 'com4'], 'text'] ] function buildLongestCommonSubstring(list, filter, favicon) { - liberator.completion.filterString = filter; + completion.filterString = filter; var filtered = []; var ignorecase = false; @@ -508,7 +508,7 @@ liberator.Completion = function () //{{{ ignorecase = true; var longest = false; - if (liberator.options["wildmode"].indexOf("longest") >= 0) + if (options["wildmode"].indexOf("longest") >= 0) longest = true; for (let [,item] in Iterator(list)) @@ -534,8 +534,8 @@ liberator.Completion = function () //{{{ break; } } - if (liberator.options.get("wildoptions").has("sort")) - filtered = filtered.sort(function (a, b) liberator.util.ciCompare(a[0], b[0]));; + if (options.get("wildoptions").has("sort")) + filtered = filtered.sort(function (a, b) util.ciCompare(a[0], b[0]));; return filtered; } @@ -545,7 +545,7 @@ liberator.Completion = function () //{{{ var filtered = []; var longest = false; - if (liberator.options["wildmode"].indexOf("longest") >= 0) + if (options["wildmode"].indexOf("longest") >= 0) longest = true; for (let [,item] in Iterator(list)) @@ -575,8 +575,8 @@ liberator.Completion = function () //{{{ break; } } - if (liberator.options.get("wildoptions").has("sort")) - filtered = filtered.sort(function (a, b) liberator.util.ciCompare(a[0], b[0]));; + if (options.get("wildoptions").has("sort")) + filtered = filtered.sort(function (a, b) util.ciCompare(a[0], b[0]));; return filtered; } @@ -696,8 +696,8 @@ liberator.Completion = function () //{{{ } filtered = filtered.concat(additionalCompletions); - if (liberator.options.get("wildoptions").has("sort")) - filtered = filtered.sort(function (a, b) liberator.util.ciCompare(a[0], b[0]));; + if (options.get("wildoptions").has("sort")) + filtered = filtered.sort(function (a, b) util.ciCompare(a[0], b[0]));; return filtered; }, @@ -725,7 +725,7 @@ liberator.Completion = function () //{{{ ////////////////////// COMPLETION TYPES //////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ - bookmark: function bookmark(filter) [0, liberator.bookmarks.get(filter)], + bookmark: function bookmark(filter) [0, bookmarks.get(filter)], // FIXME: items shouldn't be [[[a], b]], but [[a, b]] and only mapped if at all for bLCS --mst buffer: function buffer(filter) @@ -772,23 +772,23 @@ liberator.Completion = function () //{{{ if (!filter) { - for (let command in liberator.commands) + for (let command in commands) completions.push([command.name, command.description]); return [0, completions]; } - for (let command in liberator.commands) + for (let command in commands) completions.push([command.longNames, command.description]); return [0, buildLongestStartingSubstring(completions, filter)]; }, - dialog: function dialog(filter) [0, this.filter(liberator.config.dialogs || [], filter)], + dialog: function dialog(filter) [0, this.filter(config.dialogs || [], filter)], environment: function environment(filter) { let command = WINDOWS ? "set" : "export"; - let lines = liberator.io.system(command).split("\n"); + let lines = io.system(command).split("\n"); lines.splice(lines.length - 1, 1); @@ -800,7 +800,7 @@ liberator.Completion = function () //{{{ return [0, this.filter(vars, filter)]; }, - event: function event(filter) [0, this.filter(liberator.config.autocommands, filter)], + event: function event(filter) [0, this.filter(config.autocommands, filter)], // provides completions for ex commands, including their arguments ex: function ex(str) @@ -815,7 +815,7 @@ liberator.Completion = function () //{{{ } cacheFilter["ex"] = str; - var [count, cmd, special, args] = liberator.commands.parseCommand(str); + var [count, cmd, special, args] = commands.parseCommand(str); var completions = []; var start = 0; var exLength = 0; @@ -827,7 +827,7 @@ liberator.Completion = function () //{{{ return [matches[1].length, this.command(cmd)[1]]; // dynamically get completions as specified with the command's completer function - var command = liberator.commands.get(cmd); + var command = commands.get(cmd); if (command && command.completer) { matches = str.match(/^:*\d*\w+[\s!]\s*/); @@ -850,11 +850,11 @@ liberator.Completion = function () //{{{ try { - files = liberator.io.readDirectory(dir, true); + files = io.readDirectory(dir, true); - if (liberator.options["wildignore"]) + if (options["wildignore"]) { - var wigRegexp = new RegExp("(^" + liberator.options["wildignore"].replace(",", "|", "g") + ")$"); + var wigRegexp = new RegExp("(^" + options["wildignore"].replace(",", "|", "g") + ")$"); files = files.filter(function (f) f.isDirectory() || !wigRegexp.test(f.leafName)) } @@ -871,12 +871,12 @@ liberator.Completion = function () //{{{ return [dir.length, this.cached("file-" + dir, compl, generate, "filter", [true])]; else return [0, this.cached("file", filter, generate, "filter", [true])]; - }catch(e){liberator.dump(e)} + }catch(e){dump(e)} }, help: function help(filter) { - var files = liberator.config.helpFiles || []; + var files = config.helpFiles || []; var res = []; for (let i = 0; i < files.length; i++) @@ -889,7 +889,7 @@ liberator.Completion = function () //{{{ } catch (e) { - liberator.log("Error opening chrome://liberator/locale/" + files[i], 1); + log("Error opening chrome://liberator/locale/" + files[i], 1); continue; } var doc = xmlhttp.responseXML; @@ -901,7 +901,7 @@ liberator.Completion = function () //{{{ return [0, this.filter(res, filter)]; }, - history: function history(filter) [0, liberator.history.get(filter)], + history: function history(filter) [0, history.get(filter)], get javascriptCompleter() javascript, @@ -913,14 +913,14 @@ liberator.Completion = function () //{{{ } catch (e) { - liberator.dump(e); + dump(e); return [0, []]; } }, macro: function macro(filter) { - var macros = [item for (item in liberator.events.getMacros())]; + var macros = [item for (item in events.getMacros())]; return [0, this.filter(macros, filter)]; }, @@ -928,8 +928,8 @@ liberator.Completion = function () //{{{ search: function search(filter) { let [, keyword, args] = filter.match(/^\s*(\S*)\s*(.*)/); - let keywords = liberator.bookmarks.getKeywords(); - let engines = this.filter(keywords.concat(liberator.bookmarks.getSearchEngines()), filter, false, true); + let keywords = bookmarks.getKeywords(); + let engines = this.filter(keywords.concat(bookmarks.getSearchEngines()), filter, false, true); let generate = function () { let history = liberator.history.get(); @@ -964,7 +964,7 @@ liberator.Completion = function () //{{{ if (!filter) return [0, []]; - var engineList = (engineAliases || liberator.options["suggestengines"]).split(","); + var engineList = (engineAliases || options["suggestengines"]).split(","); var responseType = "application/x-suggestions+json"; var ss = Components.classes["@mozilla.org/browser/search-service;1"] .getService(Components.interfaces.nsIBrowserSearchService); @@ -1021,7 +1021,7 @@ liberator.Completion = function () //{{{ stylesheet: function stylesheet(filter) { - var completions = liberator.buffer.alternateStyleSheets.map( + var completions = buffer.alternateStyleSheets.map( function (stylesheet) [stylesheet.title, stylesheet.href || "inline"] ); @@ -1050,17 +1050,17 @@ liberator.Completion = function () //{{{ this.filterString = filter; var completions = []; var start = 0; - var skip = filter.match("^(.*" + liberator.options["urlseparator"] + ")(.*)"); // start after the last 'urlseparator' + var skip = filter.match("^(.*" + options["urlseparator"] + ")(.*)"); // start after the last 'urlseparator' if (skip) { start += skip[1].length; filter = skip[2]; } - var cpt = complete || liberator.options["complete"]; - var suggestEngineAlias = liberator.options["suggestengines"] || "google"; + var cpt = complete || options["complete"]; + var suggestEngineAlias = options["suggestengines"] || "google"; // join all completion arrays together - for (let c in liberator.util.arrayIter(cpt)) + for (let c in util.arrayIter(cpt)) { if (c == "s") completions.push(this.search(filter)[1]); @@ -1069,9 +1069,9 @@ liberator.Completion = function () //{{{ else if (c == "S") completions.push(this.searchEngineSuggest(filter, suggestEngineAlias)[1]); else if (c == "b") - completions.push(liberator.bookmarks.get(filter)); + completions.push(bookmarks.get(filter)); else if (c == "h") - completions.push(liberator.history.get(filter)); + completions.push(history.get(filter)); else if (c == "l" && completionService) // add completions like Firefox's smart location bar { completionService.stopSearch(); @@ -1086,26 +1086,22 @@ liberator.Completion = function () //{{{ } } - completionCache = liberator.util.flatten(completions); + completionCache = util.flatten(completions); return [start, completionCache.concat(historyCache)]; }, userCommand: function userCommand(filter) { - var commands = liberator.commands.getUserCommands(); - commands = commands.map(function (command) [command.name, ""]); - return [0, this.filter(commands, filter)]; + let cmds = commands.getUserCommands(); + cmds = cmds.map(function (cmd) [cmd.name, ""]); + return [0, this.filter(cmds, filter)]; }, userMapping: function userMapping(filter, modes) { // TODO: add appropriate getters to l.mappings - var mappings = []; - - for (let map in liberator.mappings.getUserIterator(modes)) - mappings.push([map.names[0], ""]); - - return [0, this.filter(mappings, filter)]; + let maps = [[m.names[0], ""] for (m in mappings.getUserIterator(modes))]; + return [0, this.filter(maps, filter)]; } // }}} }; diff --git a/content/editor.js b/content/editor.js index f4be1a0f..ce353ae4 100644 --- a/content/editor.js +++ b/content/editor.js @@ -29,7 +29,7 @@ the terms of any one of the MPL, the GPL or the LGPL. // command names taken from: // http://developer.mozilla.org/en/docs/Editor_Embedding_Guide -liberator.Editor = function () //{{{ +with (liberator) liberator.Editor = function () //{{{ { //////////////////////////////////////////////////////////////////////////////// ////////////////////// PRIVATE SECTION ///////////////////////////////////////// @@ -56,15 +56,15 @@ liberator.Editor = function () //{{{ function selectPreviousLine() { - liberator.editor.executeCommand("cmd_selectLinePrevious"); - if ((liberator.modes.extended & liberator.modes.LINE) && !liberator.editor.selectedText()) - liberator.editor.executeCommand("cmd_selectLinePrevious"); + editor.executeCommand("cmd_selectLinePrevious"); + if ((modes.extended & modes.LINE) && !editor.selectedText()) + editor.executeCommand("cmd_selectLinePrevious"); } function selectNextLine() { - liberator.editor.executeCommand("cmd_selectLineNext"); - if ((liberator.modes.extended & liberator.modes.LINE) && !liberator.editor.selectedText()) - liberator.editor.executeCommand("cmd_selectLineNext"); + editor.executeCommand("cmd_selectLineNext"); + if ((modes.extended & modes.LINE) && !editor.selectedText()) + editor.executeCommand("cmd_selectLineNext"); } // add mappings for commands like h,j,k,l,etc. in CARET, VISUAL and TEXTAREA mode @@ -72,9 +72,9 @@ liberator.Editor = function () //{{{ { var extraInfo = {}; if (hasCount) - extraInfo.flags = liberator.Mappings.flags.COUNT; + extraInfo.flags = Mappings.flags.COUNT; - liberator.mappings.add([liberator.modes.CARET], keys, "", + mappings.add([modes.CARET], keys, "", function (count) { if (typeof count != "number" || count < 1) @@ -90,7 +90,7 @@ liberator.Editor = function () //{{{ }, extraInfo); - liberator.mappings.add([liberator.modes.VISUAL], keys, "", + mappings.add([modes.VISUAL], keys, "", function (count) { if (typeof count != "number" || count < 1 || !hasCount) @@ -103,12 +103,12 @@ liberator.Editor = function () //{{{ while (count--) { - if (liberator.modes.extended & liberator.modes.TEXTAREA) + if (modes.extended & modes.TEXTAREA) { if (typeof visualTextareaCommand == "function") visualTextareaCommand(); else - liberator.editor.executeCommand(visualTextareaCommand); + editor.executeCommand(visualTextareaCommand); } else controller[caretModeMethod](caretModeArg, true); @@ -116,13 +116,13 @@ liberator.Editor = function () //{{{ }, extraInfo); - liberator.mappings.add([liberator.modes.TEXTAREA], keys, "", + mappings.add([modes.TEXTAREA], keys, "", function (count) { if (typeof count != "number" || count < 1) count = 1; - liberator.editor.executeCommand(textareaCommand, count); + editor.executeCommand(textareaCommand, count); }, extraInfo); } @@ -130,22 +130,21 @@ liberator.Editor = function () //{{{ // add mappings for commands like i,a,s,c,etc. in TEXTAREA mode function addBeginInsertModeMap(keys, commands) { - liberator.mappings.add([liberator.modes.TEXTAREA], keys, "", + mappings.add([modes.TEXTAREA], keys, "", function (count) { - for (let c = 0; c < commands.length; c++) - liberator.editor.executeCommand(commands[c], 1); - - liberator.modes.set(liberator.modes.INSERT, liberator.modes.TEXTAREA); + commands.forEach(function (cmd) + editor.executeCommand(cmd, 1)); + modes.set(modes.INSERT, modes.TEXTAREA); }); } function addMotionMap(key) { - liberator.mappings.add([liberator.modes.TEXTAREA], [key], + mappings.add([modes.TEXTAREA], [key], "Motion command", - function (motion, count) { liberator.editor.executeCommandWithMotion(key, motion, count); }, - { flags: liberator.Mappings.flags.MOTION | liberator.Mappings.flags.COUNT }); + function (motion, count) { editor.executeCommandWithMotion(key, motion, count); }, + { flags: Mappings.flags.MOTION | Mappings.flags.COUNT }); } // mode = "i" -> add :iabbrev, :iabclear and :iunabbrev commands @@ -154,31 +153,31 @@ liberator.Editor = function () //{{{ var mode = ch || "!"; modeDescription = modeDescription ? " in " + modeDescription + " mode" : ""; - liberator.commands.add([ch ? ch + "a[bbrev]" : "ab[breviate]"], + commands.add([ch ? ch + "a[bbrev]" : "ab[breviate]"], "Abbreviate a key sequence" + modeDescription, function (args) { if (!args) { - liberator.editor.listAbbreviations(mode, ""); + editor.listAbbreviations(mode, ""); return; } var matches = args.match(/^(\S+)(?:\s+(.+))?$/); var [lhs, rhs] = [matches[1], matches[2]]; if (rhs) - liberator.editor.addAbbreviation(mode, lhs, rhs); + editor.addAbbreviation(mode, lhs, rhs); else - liberator.editor.listAbbreviations(mode, lhs); + editor.listAbbreviations(mode, lhs); }); - liberator.commands.add([ch ? ch + "una[bbrev]" : "una[bbreviate]"], + commands.add([ch ? ch + "una[bbrev]" : "una[bbreviate]"], "Remove an abbreviation" + modeDescription, - function (args) { liberator.editor.removeAbbreviation(mode, args); }); + function (args) { editor.removeAbbreviation(mode, args); }); - liberator.commands.add([ch + "abc[lear]"], + commands.add([ch + "abc[lear]"], "Remove all abbreviations" + modeDescription, - function () { liberator.editor.removeAllAbbreviations(mode); }, + function () { editor.removeAllAbbreviations(mode); }, { argCount: "0" }); } @@ -186,11 +185,11 @@ liberator.Editor = function () //{{{ ////////////////////// OPTIONS ///////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ - liberator.options.add(["editor"], + options.add(["editor"], "Set the external text editor", "string", "gvim -f"); - liberator.options.add(["insertmode", "im"], + options.add(["insertmode", "im"], "Use Insert mode as the default for text areas", "boolean", true); @@ -198,7 +197,7 @@ liberator.Editor = function () //{{{ ////////////////////// MAPPINGS //////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ - var modes = [liberator.modes.INSERT, liberator.modes.COMMAND_LINE]; + var myModes = [modes.INSERT, modes.COMMAND_LINE]; /* KEYS COUNT CARET TEXTAREA VISUAL_TEXTAREA */ addMovementMap(["k", ""], true, "lineMove", false, "cmd_linePrevious", selectPreviousLine); @@ -227,253 +226,253 @@ liberator.Editor = function () //{{{ addMotionMap("y"); // yank // insert mode mappings - liberator.mappings.add(modes, + mappings.add(myModes, ["", "", "", "", ""], - "Ignore certain " + liberator.config.hostApplication + " key bindings", - function () { /*liberator.beep();*/ }); + "Ignore certain " + config.hostApplication + " key bindings", + function () { /*beep();*/ }); - liberator.mappings.add(modes, + mappings.add(myModes, [""], "Delete previous word", - function () { liberator.editor.executeCommand("cmd_deleteWordBackward", 1); }); + function () { editor.executeCommand("cmd_deleteWordBackward", 1); }); - liberator.mappings.add(modes, + mappings.add(myModes, [""], "Delete until beginning of current line", function () { // broken in FF3, deletes the whole line: - // liberator.editor.executeCommand("cmd_deleteToBeginningOfLine", 1); - liberator.editor.executeCommand("cmd_selectBeginLine", 1); + // editor.executeCommand("cmd_deleteToBeginningOfLine", 1); + editor.executeCommand("cmd_selectBeginLine", 1); if (getController().isCommandEnabled("cmd_delete")) - liberator.editor.executeCommand("cmd_delete", 1); + editor.executeCommand("cmd_delete", 1); }); - liberator.mappings.add(modes, + mappings.add(myModes, [""], "Delete until end of current line", - function () { liberator.editor.executeCommand("cmd_deleteToEndOfLine", 1); }); + function () { editor.executeCommand("cmd_deleteToEndOfLine", 1); }); - liberator.mappings.add(modes, + mappings.add(myModes, [""], "Move cursor to beginning of current line", - function () { liberator.editor.executeCommand("cmd_beginLine", 1); }); + function () { editor.executeCommand("cmd_beginLine", 1); }); - liberator.mappings.add(modes, + mappings.add(myModes, [""], "Move cursor to end of current line", - function () { liberator.editor.executeCommand("cmd_endLine", 1); }); + function () { editor.executeCommand("cmd_endLine", 1); }); - liberator.mappings.add(modes, + mappings.add(myModes, [""], "Delete character to the left", - function () { liberator.editor.executeCommand("cmd_deleteCharBackward", 1); }); + function () { editor.executeCommand("cmd_deleteCharBackward", 1); }); - liberator.mappings.add(modes, + mappings.add(myModes, [""], "Delete character to the right", - function () { liberator.editor.executeCommand("cmd_deleteCharForward", 1); }); + function () { editor.executeCommand("cmd_deleteCharForward", 1); }); - /*liberator.mappings.add(modes, + /*mappings.add(myModes, [""], "Move cursor to beginning of text field", - function () { liberator.editor.executeCommand("cmd_moveTop", 1); }); + function () { editor.executeCommand("cmd_moveTop", 1); }); - liberator.mappings.add(modes, + mappings.add(myModes, [""], "Move cursor to end of text field", - function () { liberator.editor.executeCommand("cmd_moveBottom", 1); });*/ + function () { editor.executeCommand("cmd_moveBottom", 1); });*/ - liberator.mappings.add(modes, + mappings.add(myModes, [""], "Insert clipboard/selection", - function () { liberator.editor.pasteClipboard(); }); + function () { editor.pasteClipboard(); }); - liberator.mappings.add([liberator.modes.INSERT, liberator.modes.TEXTAREA, liberator.modes.COMPOSE], + mappings.add([modes.INSERT, modes.TEXTAREA, modes.COMPOSE], [""], "Edit text field with an external editor", - function () { liberator.editor.editWithExternalEditor(); }); + function () { editor.editWithExternalEditor(); }); // FIXME: does not work correctly - liberator.mappings.add([liberator.modes.INSERT], + mappings.add([modes.INSERT], [""], "Edit text field in vi mode", function () { liberator.mode = liberator.modes.TEXTAREA; }); - liberator.mappings.add([liberator.modes.INSERT], + mappings.add([modes.INSERT], ["", ""], "Expand insert mode abbreviation", - function () { liberator.editor.expandAbbreviation("i"); }, - { flags: liberator.Mappings.flags.ALLOW_EVENT_ROUTING }); + function () { editor.expandAbbreviation("i"); }, + { flags: Mappings.flags.ALLOW_EVENT_ROUTING }); - liberator.mappings.add([liberator.modes.INSERT], + mappings.add([modes.INSERT], [""], "Expand insert mode abbreviation", - function () { liberator.editor.expandAbbreviation("i"); document.commandDispatcher.advanceFocus(); }); + function () { editor.expandAbbreviation("i"); document.commandDispatcher.advanceFocus(); }); - liberator.mappings.add([liberator.modes.INSERT], + mappings.add([modes.INSERT], ["", ""], "Expand insert mode abbreviation", - function () { liberator.editor.expandAbbreviation("i"); }); + function () { editor.expandAbbreviation("i"); }); // textarea mode - liberator.mappings.add([liberator.modes.TEXTAREA], + mappings.add([modes.TEXTAREA], ["u"], "Undo", function (count) { - liberator.editor.executeCommand("cmd_undo", count); + editor.executeCommand("cmd_undo", count); liberator.mode = liberator.modes.TEXTAREA; }, - { flags: liberator.Mappings.flags.COUNT }); + { flags: Mappings.flags.COUNT }); - liberator.mappings.add([liberator.modes.TEXTAREA], + mappings.add([modes.TEXTAREA], [""], "Redo", function (count) { - liberator.editor.executeCommand("cmd_redo", count); + editor.executeCommand("cmd_redo", count); liberator.mode = liberator.modes.TEXTAREA; }, - { flags: liberator.Mappings.flags.COUNT }); + { flags: Mappings.flags.COUNT }); - liberator.mappings.add([liberator.modes.TEXTAREA], + mappings.add([modes.TEXTAREA], ["D"], "Delete the characters under the cursor until the end of the line", - function () { liberator.editor.executeCommand("cmd_deleteToEndOfLine"); }); + function () { editor.executeCommand("cmd_deleteToEndOfLine"); }); - liberator.mappings.add([liberator.modes.TEXTAREA], + mappings.add([modes.TEXTAREA], ["o"], "Open line below current", function (count) { - liberator.editor.executeCommand("cmd_endLine", 1); - liberator.modes.set(liberator.modes.INSERT, liberator.modes.TEXTAREA); - liberator.events.feedkeys(""); + editor.executeCommand("cmd_endLine", 1); + modes.set(modes.INSERT, modes.TEXTAREA); + events.feedkeys(""); }); - liberator.mappings.add([liberator.modes.TEXTAREA], + mappings.add([modes.TEXTAREA], ["O"], "Open line above current", function (count) { - liberator.editor.executeCommand("cmd_beginLine", 1); - liberator.modes.set(liberator.modes.INSERT, liberator.modes.TEXTAREA); - liberator.events.feedkeys(""); - liberator.editor.executeCommand("cmd_linePrevious", 1); + editor.executeCommand("cmd_beginLine", 1); + modes.set(modes.INSERT, modes.TEXTAREA); + events.feedkeys(""); + editor.executeCommand("cmd_linePrevious", 1); }); - liberator.mappings.add([liberator.modes.TEXTAREA], + mappings.add([modes.TEXTAREA], ["X"], "Delete character to the left", - function (count) { liberator.editor.executeCommand("cmd_deleteCharBackward", count); }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { editor.executeCommand("cmd_deleteCharBackward", count); }, + { flags: Mappings.flags.COUNT }); - liberator.mappings.add([liberator.modes.TEXTAREA], + mappings.add([modes.TEXTAREA], ["x"], "Delete character to the right", - function (count) { liberator.editor.executeCommand("cmd_deleteCharForward", count); }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { editor.executeCommand("cmd_deleteCharForward", count); }, + { flags: Mappings.flags.COUNT }); // visual mode - liberator.mappings.add([liberator.modes.CARET, liberator.modes.TEXTAREA, liberator.modes.VISUAL], + mappings.add([modes.CARET, modes.TEXTAREA, modes.VISUAL], ["v"], "Start visual mode", - function (count) { liberator.modes.set(liberator.modes.VISUAL, liberator.mode); }); + function (count) { modes.set(modes.VISUAL, mode); }); - liberator.mappings.add([liberator.modes.TEXTAREA], + mappings.add([modes.TEXTAREA], ["V"], "Start visual line mode", function (count) { - liberator.modes.set(liberator.modes.VISUAL, liberator.modes.TEXTAREA | liberator.modes.LINE); - liberator.editor.executeCommand("cmd_beginLine", 1); - liberator.editor.executeCommand("cmd_selectLineNext", 1); + modes.set(modes.VISUAL, modes.TEXTAREA | modes.LINE); + editor.executeCommand("cmd_beginLine", 1); + editor.executeCommand("cmd_selectLineNext", 1); }); - liberator.mappings.add([liberator.modes.VISUAL], + mappings.add([modes.VISUAL], ["c", "s"], "Change selected text", function (count) { - if (liberator.modes.extended & liberator.modes.TEXTAREA) + if (modes.extended & modes.TEXTAREA) { - liberator.editor.executeCommand("cmd_cut"); - liberator.modes.set(liberator.modes.INSERT, liberator.modes.TEXTAREA); + editor.executeCommand("cmd_cut"); + modes.set(modes.INSERT, modes.TEXTAREA); } else - liberator.beep(); + beep(); }); - liberator.mappings.add([liberator.modes.VISUAL], + mappings.add([modes.VISUAL], ["d"], "Delete selected text", function (count) { - if (liberator.modes.extended & liberator.modes.TEXTAREA) + if (modes.extended & modes.TEXTAREA) { - liberator.editor.executeCommand("cmd_cut"); - liberator.modes.set(liberator.modes.TEXTAREA); + editor.executeCommand("cmd_cut"); + modes.set(modes.TEXTAREA); } else - liberator.beep(); + beep(); }); - liberator.mappings.add([liberator.modes.VISUAL], + mappings.add([modes.VISUAL], ["y"], "Yank selected text", function (count) { - if (liberator.modes.extended & liberator.modes.TEXTAREA) + if (modes.extended & modes.TEXTAREA) { - liberator.editor.executeCommand("cmd_copy"); - liberator.modes.set(liberator.modes.TEXTAREA); + editor.executeCommand("cmd_copy"); + modes.set(modes.TEXTAREA); } else { var sel = window.content.document.getSelection(); if (sel) - liberator.util.copyToClipboard(sel, true); + util.copyToClipboard(sel, true); else - liberator.beep(); + beep(); } }); - liberator.mappings.add([liberator.modes.VISUAL, liberator.modes.TEXTAREA], + mappings.add([modes.VISUAL, modes.TEXTAREA], ["p"], "Paste clipboard contents", function (count) { - if (!(liberator.modes.extended & liberator.modes.CARET)) + if (!(modes.extended & modes.CARET)) { if (!count) count = 1; while (count--) - liberator.editor.executeCommand("cmd_paste"); + editor.executeCommand("cmd_paste"); liberator.mode = liberator.modes.TEXTAREA; } else - liberator.beep(); + beep(); }); // finding characters - liberator.mappings.add([liberator.modes.TEXTAREA, liberator.modes.VISUAL], + mappings.add([modes.TEXTAREA, modes.VISUAL], ["f"], "Move to a character on the current line after the cursor", function (count, arg) { - var pos = liberator.editor.findCharForward(arg, count); + var pos = editor.findCharForward(arg, count); if (pos >= 0) - liberator.editor.moveToPosition(pos, true, liberator.mode == liberator.modes.VISUAL); + editor.moveToPosition(pos, true, mode == modes.VISUAL); }, - { flags: liberator.Mappings.flags.ARGUMENT | liberator.Mappings.flags.COUNT }); + { flags: Mappings.flags.ARGUMENT | Mappings.flags.COUNT }); - liberator.mappings.add([liberator.modes.TEXTAREA, liberator.modes.VISUAL], + mappings.add([modes.TEXTAREA, modes.VISUAL], ["F"], "Move to a charater on the current line before the cursor", function (count, arg) { - var pos = liberator.editor.findCharBackward(arg, count); + var pos = editor.findCharBackward(arg, count); if (pos >= 0) - liberator.editor.moveToPosition(pos, false, liberator.mode == liberator.modes.VISUAL); + editor.moveToPosition(pos, false, mode == modes.VISUAL); }, - { flags: liberator.Mappings.flags.ARGUMENT | liberator.Mappings.flags.COUNT }); + { flags: Mappings.flags.ARGUMENT | Mappings.flags.COUNT }); - liberator.mappings.add([liberator.modes.TEXTAREA, liberator.modes.VISUAL], + mappings.add([modes.TEXTAREA, modes.VISUAL], ["t"], "Move before a character on the current line", function (count, arg) { - var pos = liberator.editor.findCharForward(arg, count); + var pos = editor.findCharForward(arg, count); if (pos >= 0) - liberator.editor.moveToPosition(pos - 1, true, liberator.mode == liberator.modes.VISUAL); + editor.moveToPosition(pos - 1, true, mode == modes.VISUAL); }, - { flags: liberator.Mappings.flags.ARGUMENT | liberator.Mappings.flags.COUNT }); + { flags: Mappings.flags.ARGUMENT | Mappings.flags.COUNT }); - liberator.mappings.add([liberator.modes.TEXTAREA, liberator.modes.VISUAL], + mappings.add([modes.TEXTAREA, modes.VISUAL], ["T"], "Move before a character on the current line, backwards", function (count, arg) { - var pos = liberator.editor.findCharBackward(arg, count); + var pos = editor.findCharBackward(arg, count); if (pos >= 0) - liberator.editor.moveToPosition(pos + 1, false, liberator.mode == liberator.modes.VISUAL); + editor.moveToPosition(pos + 1, false, mode == modes.VISUAL); }, - { flags: liberator.Mappings.flags.ARGUMENT | liberator.Mappings.flags.COUNT }); + { flags: Mappings.flags.ARGUMENT | Mappings.flags.COUNT }); // textarea and visual mode - liberator.mappings.add([liberator.modes.TEXTAREA, liberator.modes.VISUAL], + mappings.add([modes.TEXTAREA, modes.VISUAL], ["~"], "Switch case of the character under the cursor and move the cursor to the right", function (count) { - if (liberator.modes.main == liberator.modes.VISUAL) + if (modes.main == modes.VISUAL) { count = editor().selectionEnd - editor().selectionStart; } @@ -488,18 +487,18 @@ liberator.Editor = function () //{{{ var pos = editor().selectionStart; if (pos >= text.length) { - liberator.beep(); + beep(); return; } var chr = text[pos]; editor().value = text.substring(0, pos) + (chr == chr.toLocaleLowerCase() ? chr.toLocaleUpperCase() : chr.toLocaleLowerCase()) + text.substring(pos + 1); - liberator.editor.moveToPosition(pos + 1, true, false); + editor.moveToPosition(pos + 1, true, false); } - liberator.modes.set(liberator.modes.TEXTAREA); + modes.set(modes.TEXTAREA); }, - { flags: liberator.Mappings.flags.COUNT }); + { flags: Mappings.flags.COUNT }); /////////////////////////////////////////////////////////////////////////////}}} ////////////////////// COMMANDS //////////////////////////////////////////////// @@ -555,14 +554,14 @@ liberator.Editor = function () //{{{ { var elt = window.document.commandDispatcher.focusedElement; - if (elt.setSelectionRange && liberator.util.readFromClipboard()) + if (elt.setSelectionRange && util.readFromClipboard()) // readFromClipboard would return 'undefined' if not checked // dunno about .setSelectionRange { var rangeStart = elt.selectionStart; // caret position var rangeEnd = elt.selectionEnd; var tempStr1 = elt.value.substring(0, rangeStart); - var tempStr2 = liberator.util.readFromClipboard(); + var tempStr2 = util.readFromClipboard(); var tempStr3 = elt.value.substring(rangeEnd); elt.value = tempStr1 + tempStr2 + tempStr3; elt.selectionStart = rangeStart + tempStr2.length; @@ -576,7 +575,7 @@ liberator.Editor = function () //{{{ var controller = getController(); if (!controller || !controller.supportsCommand(cmd) || !controller.isCommandEnabled(cmd)) { - liberator.beep(); + beep(); return false; } @@ -597,7 +596,7 @@ liberator.Editor = function () //{{{ catch (e) { if (!didCommand) - liberator.beep(); + beep(); return false; } } @@ -618,7 +617,7 @@ liberator.Editor = function () //{{{ count--; } - liberator.modes.set(liberator.modes.VISUAL, liberator.modes.TEXTAREA); + modes.set(modes.VISUAL, modes.TEXTAREA); switch (motion) { @@ -663,7 +662,7 @@ liberator.Editor = function () //{{{ break; default: - liberator.beep(); + beep(); return false; } @@ -672,11 +671,11 @@ liberator.Editor = function () //{{{ case "d": this.executeCommand("cmd_delete", 1); // need to reset the mode as the visual selection changes it - liberator.modes.main = liberator.modes.TEXTAREA; + modes.main = modes.TEXTAREA; break; case "c": this.executeCommand("cmd_delete", 1); - liberator.modes.set(liberator.modes.INSERT, liberator.modes.TEXTAREA); + modes.set(modes.INSERT, modes.TEXTAREA); break; case "y": this.executeCommand("cmd_copy", 1); @@ -684,7 +683,7 @@ liberator.Editor = function () //{{{ break; default: - liberator.beep(); + beep(); return false; } return true; @@ -749,7 +748,7 @@ liberator.Editor = function () //{{{ return i + 1; // always position the cursor after the char } - liberator.beep(); + beep(); return -1; }, @@ -776,7 +775,7 @@ liberator.Editor = function () //{{{ return i; } - liberator.beep(); + beep(); return -1; }, @@ -784,7 +783,7 @@ liberator.Editor = function () //{{{ editWithExternalEditor: function () { var textBox = null; - if (!(liberator.config.isComposeWindow)) + if (!(config.isComposeWindow)) textBox = document.commandDispatcher.focusedElement; var text = ""; @@ -795,30 +794,30 @@ liberator.Editor = function () //{{{ else return false; - var editor = liberator.options["editor"]; - var args = liberator.commands.parseArgs(editor, [], "*", true).arguments; + var editor = options["editor"]; + var args = commands.parseArgs(editor, [], "*", true).arguments; if (args.length < 1) { - liberator.echoerr("No editor specified"); + echoerr("No editor specified"); return false; } try { - var tmpfile = liberator.io.createTempFile(); + var tmpfile = io.createTempFile(); } catch (e) { - liberator.echoerr("Could not create temporary file: " + e.message); + echoerr("Could not create temporary file: " + e.message); return false; } try { - liberator.io.writeFile(tmpfile, text); + io.writeFile(tmpfile, text); } catch (e) { - liberator.echoerr("Could not write to temporary file " + tmpfile.path + ": " + e.message); + echoerr("Could not write to temporary file " + tmpfile.path + ": " + e.message); return false; } @@ -834,7 +833,7 @@ liberator.Editor = function () //{{{ } // TODO: save return value in v:shell_error - liberator.callFunctionInThread(null, liberator.io.run, [prog, args, true]); + callFunctionInThread(null, io.run, [prog, args, true]); if (textBox) textBox.removeAttribute("readonly"); @@ -842,13 +841,13 @@ liberator.Editor = function () //{{{ // if (v:shell_error != 0) // { // tmpBg = "red"; - // liberator.echoerr("External editor returned with exit code " + retcode); + // echoerr("External editor returned with exit code " + retcode); // } // else // { try { - var val = liberator.io.readFile(tmpfile); + var val = io.readFile(tmpfile); if (textBox) textBox.value = val; else @@ -869,7 +868,7 @@ liberator.Editor = function () //{{{ catch (e) { tmpBg = "red"; - liberator.echoerr("Could not read from temporary file " + tmpfile.path + ": " + e.message); + echoerr("Could not read from temporary file " + tmpfile.path + ": " + e.message); } // } @@ -916,11 +915,11 @@ liberator.Editor = function () //{{{ for (let i = 0; i < abbrev[lhs].length; i++) { if (abbrev[lhs][i][0] == filter) - liberator.echo(abbrev[lhs][i][0] + " " + lhs + " " + abbrev[lhs][i][1]); + echo(abbrev[lhs][i][0] + " " + lhs + " " + abbrev[lhs][i][1]); return true; } } - liberator.echoerr("No abbreviations found"); + echoerr("No abbreviations found"); return false; } else // list all (for that filter {i,c,!}) @@ -931,8 +930,8 @@ liberator.Editor = function () //{{{ let list = { - liberator.template.map(abbrev, function ([lhs, rhs]) - liberator.template.map(rhs, function (abbr) + template.map(abbrev, function ([lhs, rhs]) + template.map(rhs, function (abbr) searchFilter.indexOf(abbr[0]) < 0 ? undefined : @@ -942,9 +941,9 @@ liberator.Editor = function () //{{{ }
{abbr[0]}
; if (list.*.length()) - liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); + commandline.echo(list, commandline.HL_NORMAL, commandline.FORCE_MULTILINE); else - liberator.echoerr("No abbreviations found"); + echoerr("No abbreviations found"); } }, @@ -1034,7 +1033,7 @@ liberator.Editor = function () //{{{ { if (!lhs) { - liberator.echoerr("E474: Invalid argument"); + echoerr("E474: Invalid argument"); return false; } @@ -1072,7 +1071,7 @@ liberator.Editor = function () //{{{ } } - liberator.echoerr("E24: No such abbreviation"); + echoerr("E24: No such abbreviation"); return false; }, diff --git a/content/events.js b/content/events.js index b72a6a3a..7ca76b13 100644 --- a/content/events.js +++ b/content/events.js @@ -26,7 +26,7 @@ the provisions above, a recipient may use your version of this file under the terms of any one of the MPL, the GPL or the LGPL. }}} ***** END LICENSE BLOCK *****/ -liberator.AutoCommands = function () //{{{ +with (liberator) liberator.AutoCommands = function () //{{{ { //////////////////////////////////////////////////////////////////////////////// ////////////////////// PRIVATE SECTION ///////////////////////////////////////// @@ -44,23 +44,22 @@ liberator.AutoCommands = function () //{{{ ////////////////////// OPTIONS ///////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ - liberator.options.add(["eventignore", "ei"], + options.add(["eventignore", "ei"], "List of autocommand event names which should be ignored", "stringlist", "", { - completer: function (value) Array(liberator.config.autocommands).push(["all", "All events"]), + completer: function (value) Array(config.autocommands).push(["all", "All events"]), validator: function (value) { let values = value.split(","); - let events = liberator.config.autocommands.map(function (event) event[0]); - + let events = config.autocommands.map(function (event) event[0]); events.push("all"); return values.every(function (event) events.indexOf(event) >= 0); } }); - liberator.options.add(["focuscontent", "fc"], + options.add(["focuscontent", "fc"], "Try to stay in normal mode after loading a web page", "boolean", false); @@ -68,7 +67,7 @@ liberator.AutoCommands = function () //{{{ ////////////////////// COMMANDS //////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ - liberator.commands.add(["au[tocmd]"], + commands.add(["au[tocmd]"], "Execute commands automatically on events", function (args, special) { @@ -78,13 +77,13 @@ liberator.AutoCommands = function () //{{{ if (event) { // NOTE: event can only be a comma separated list for |:au {event} {pat} {cmd}| - let validEvents = liberator.config.autocommands.map(function (event) event[0]); + let validEvents = config.autocommands.map(function (event) event[0]); validEvents.push("*"); events = event.split(","); if (!events.every(function (event) validEvents.indexOf(event) >= 0)) { - liberator.echoerr("E216: No such group or event: " + event); + echoerr("E216: No such group or event: " + event); return; } } @@ -92,8 +91,8 @@ liberator.AutoCommands = function () //{{{ if (cmd) // add new command, possibly removing all others with the same event/pattern { if (special) - liberator.autocommands.remove(event, regex); - liberator.autocommands.add(events, regex, cmd); + autocommands.remove(event, regex); + autocommands.add(events, regex, cmd); } else { @@ -103,11 +102,11 @@ liberator.AutoCommands = function () //{{{ { // TODO: "*" only appears to work in Vim when there is a {group} specified if (args.arguments[0] != "*" || regex) - liberator.autocommands.remove(event, regex); // remove all + autocommands.remove(event, regex); // remove all } else { - liberator.autocommands.list(event, regex); // list all + autocommands.list(event, regex); // list all } } }, @@ -115,56 +114,56 @@ liberator.AutoCommands = function () //{{{ argCount: 2, bang: true, literal: true, - completer: function (filter) liberator.completion.event(filter) + completer: function (filter) completion.event(filter) }); // TODO: expand target to all buffers - liberator.commands.add(["doauto[all]"], + commands.add(["doauto[all]"], "Apply the autocommands matching the specified URL pattern to all buffers", function (args) { - liberator.commands.get("doautocmd").action.call(this, args); + commands.get("doautocmd").action.call(this, args); }, { argCount: "+", - completer: function (filter) liberator.completion.event(filter) + completer: function (filter) completion.event(filter) } ); // TODO: restrict target to current buffer - liberator.commands.add(["do[autocmd]"], + commands.add(["do[autocmd]"], "Apply the autocommands matching the specified URL pattern to the current buffer", function (args) { args = args.string; let [, event, url] = args.match(/^(\S+)(?:\s+(\S+))?$/); - url = url || liberator.buffer.URL; + url = url || buffer.URL; - let validEvents = liberator.config.autocommands.map(function (e) e[0]); + let validEvents = config.autocommands.map(function (e) e[0]); if (event == "*") { - liberator.echoerr("E217: Can't execute autocommands for ALL events"); + echoerr("E217: Can't execute autocommands for ALL events"); } else if (validEvents.indexOf(event) == -1) { - liberator.echoerr("E216: No such group or event: " + args); + echoerr("E216: No such group or event: " + args); } else { // TODO: perhaps trigger could return the number of autocmds triggered // TODO: Perhaps this should take -args to pass to the command? - if (!liberator.autocommands.get(event).some(function (c) c.pattern.test(url))) - liberator.echo("No matching autocommands"); + if (!autocommands.get(event).some(function (c) c.pattern.test(url))) + echo("No matching autocommands"); else - liberator.autocommands.trigger(event, {url: url}); + autocommands.trigger(event, {url: url}); } }, { // TODO: Vim actually just displays "No matching autocommands" when no arg is specified argCount: "+", - completer: function (filter) liberator.completion.event(filter) + completer: function (filter) completion.event(filter) } ); @@ -185,12 +184,10 @@ liberator.AutoCommands = function () //{{{ if (typeof events == "string") { events = events.split(","); - liberator.log("DEPRECATED: the events list arg to autocommands.add() should be an array of event names"); + log("DEPRECATED: the events list arg to autocommands.add() should be an array of event names"); } - - events.forEach( - function (event) { store.push({event: event, pattern: RegExp(regex), command: cmd}); } - ); + events.forEach(function (event) + store.push({event: event, pattern: RegExp(regex), command: cmd})); }, get: function (event, regex) @@ -216,18 +213,18 @@ liberator.AutoCommands = function () //{{{ } }); - var list = liberator.template.generic( + var list = template.generic( { - liberator.template.map(cmds, function ([event, items]) + template.map(cmds, function ([event, items]) + - liberator.template.map(items, function (item) + template.map(items, function (item) @@ -235,19 +232,17 @@ liberator.AutoCommands = function () //{{{ }
----- Auto Commands -----
{event}
 {item.pattern.source} {item.command}
); - liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); + commandline.echo(list, commandline.HL_NORMAL, commandline.FORCE_MULTILINE); }, trigger: function (event, args) { - let events = liberator.options["eventignore"].split(","); - - if (liberator.options.get("eventignore").has("all", event)) + if (options.get("eventignore").has("all", event)) return; let autoCmds = store.filter(function (autoCmd) autoCmd.event == event); - liberator.echomsg("Executing " + event + " Auto commands for \"*\"", 8); + echomsg("Executing " + event + " Auto commands for \"*\"", 8); let lastPattern = null; @@ -257,12 +252,12 @@ liberator.AutoCommands = function () //{{{ if (autoCmd.pattern.test(url)) { if (!lastPattern || lastPattern.source != autoCmd.pattern.source) - liberator.echomsg("Executing " + event + " Auto commands for \"" + autoCmd.pattern.source + "\"", 8); + echomsg("Executing " + event + " Auto commands for \"" + autoCmd.pattern.source + "\"", 8); lastPattern = autoCmd.pattern; - liberator.echomsg("autocommand " + autoCmd.command, 9); - liberator.execute(liberator.commands.replaceTokens(autoCmd.command, args)); + echomsg("autocommand " + autoCmd.command, 9); + execute(commands.replaceTokens(autoCmd.command, args)); } } } @@ -270,7 +265,7 @@ liberator.AutoCommands = function () //{{{ //}}} }; //}}} -liberator.Events = function () //{{{ +with (liberator) liberator.Events = function () //{{{ { //////////////////////////////////////////////////////////////////////////////// ////////////////////// PRIVATE SECTION ///////////////////////////////////////// @@ -279,7 +274,7 @@ liberator.Events = function () //{{{ var inputBufferLength = 0; // count the number of keys in v.input.buffer (can be different from v.input.buffer.length) var skipMap = false; // while feeding the keys (stored in v.input.buffer | no map found) - ignore mappings - var macros = liberator.storage.newMap('macros', true); + var macros = storage.newMap('macros', true); var currentMacro = ""; var lastMacro = ""; @@ -291,27 +286,27 @@ liberator.Events = function () //{{{ { tabcontainer.addEventListener("TabMove", function (event) { - liberator.statusline.updateTabCount(); + statusline.updateTabCount(); }, false); tabcontainer.addEventListener("TabOpen", function (event) { - liberator.statusline.updateTabCount(); + statusline.updateTabCount(); }, false); tabcontainer.addEventListener("TabClose", function (event) { - liberator.statusline.updateTabCount(); + statusline.updateTabCount(); }, false); tabcontainer.addEventListener("TabSelect", function (event) { // TODO: is all of that necessary? - liberator.modes.reset(); - liberator.commandline.clear(); - liberator.modes.show(); - liberator.statusline.updateTabCount(); - liberator.tabs.updateSelectionHistory(); + modes.reset(); + commandline.clear(); + modes.show(); + statusline.updateTabCount(); + tabs.updateSelectionHistory(); - if (liberator.options["focuscontent"]) - setTimeout(function () { liberator.focusContent(true); }, 10); // just make sure, that no widget has focus + if (options["focuscontent"]) + setTimeout(function () { focusContent(true); }, 10); // just make sure, that no widget has focus }, false); } @@ -324,8 +319,8 @@ liberator.Events = function () //{{{ // called when the active document is scrolled getBrowser().addEventListener("scroll", function (event) { - liberator.statusline.updateBufferPosition(); - liberator.modes.show(); + statusline.updateBufferPosition(); + modes.show(); }, null); } catch (e) {} @@ -334,7 +329,7 @@ liberator.Events = function () //{{{ // { // // reset buffer loading state as early as possible, important for macros // dump("submit\n"); -// liberator.buffer.loaded = 0; +// buffer.loaded = 0; // }, null); ///////////////////////////////////////////////////////// @@ -345,23 +340,23 @@ liberator.Events = function () //{{{ if (event.originalTarget.localName == "tooltip" || event.originalTarget.id == "liberator-visualbell") return; - liberator.modes.add(liberator.modes.MENU); + modes.add(modes.MENU); } function exitPopupMode() { // gContextMenu is set to NULL by Firefox, when a context menu is closed if (typeof gContextMenu != "undefined" && gContextMenu == null && !activeMenubar) - liberator.modes.remove(liberator.modes.MENU); + modes.remove(modes.MENU); } function enterMenuMode() { activeMenubar = true; - liberator.modes.add(liberator.modes.MENU); + modes.add(modes.MENU); } function exitMenuMode() { activeMenubar = false; - liberator.modes.remove(liberator.modes.MENU); + modes.remove(modes.MENU); } window.addEventListener("popupshown", enterPopupMode, true); window.addEventListener("popuphidden", exitPopupMode, true); @@ -370,7 +365,7 @@ liberator.Events = function () //{{{ // window.document.addEventListener("DOMTitleChanged", function (event) // { - // liberator.log("titlechanged"); + // log("titlechanged"); // }, null); // NOTE: the order of ["Esc", "Escape"] or ["Escape", "Esc"] @@ -471,9 +466,9 @@ liberator.Events = function () //{{{ title: doc.title } if (liberator.has("tabs")) - args.tab = liberator.tabs.getContentIndex(doc) + 1; + args.tab = tabs.getContentIndex(doc) + 1; - liberator.autocommands.trigger(name, args); + autocommands.trigger(name, args); } function onDOMContentLoaded(event) @@ -494,7 +489,7 @@ liberator.Events = function () //{{{ // hacky way to get rid of "Transfering data from ..." on sites with frames // when you click on a link inside a frameset, because asyncUpdateUI // is not triggered there (firefox bug?) - setTimeout(liberator.statusline.updateUrl, 10); + setTimeout(statusline.updateUrl, 10); return; } @@ -504,10 +499,10 @@ liberator.Events = function () //{{{ let title = doc.title; // update history - if (url && liberator.history) - liberator.history.add(url, title); + if (url && history) + history.add(url, title); - // mark the buffer as loaded, we can't use liberator.buffer.loaded + // mark the buffer as loaded, we can't use buffer.loaded // since that always refers to the current buffer, while doc can be // any buffer, even in a background tab doc.pageIsFullyLoaded = 1; @@ -517,7 +512,7 @@ liberator.Events = function () //{{{ { // we want to stay in command mode after a page has loaded // TODO: move somehwere else, as focusing can already happen earlier than on "load" - if (liberator.options["focuscontent"]) + if (options["focuscontent"]) { setTimeout(function () { var focused = document.commandDispatcher.focusedElement; @@ -528,7 +523,7 @@ liberator.Events = function () //{{{ } else // background tab { - liberator.echomsg("Background tab loaded: " + title || url, 1); + echomsg("Background tab loaded: " + title || url, 1); } triggerLoadAutocmd("PageLoad", doc); @@ -546,9 +541,9 @@ liberator.Events = function () //{{{ catch (e) { if (e.message == "Interrupted") - liberator.echoerr("Interrupted"); + echoerr("Interrupted"); else - liberator.echoerr("Processing " + event.type + " event: " + (e.echoerr || e)); + echoerr("Processing " + event.type + " event: " + (e.echoerr || e)); if (Components.utils.reportError) Components.utils.reportError(e); } @@ -558,63 +553,63 @@ liberator.Events = function () //{{{ // return true when load successful, or false otherwise function waitForPageLoaded() { - liberator.dump("start waiting in loaded state: " + liberator.buffer.loaded); - liberator.threadYield(true); // clear queue + dump("start waiting in loaded state: " + buffer.loaded); + threadYield(true); // clear queue - if (liberator.buffer.loaded == 1) + if (buffer.loaded == 1) return true; var ms = 25000; // maximum time to wait - TODO: add option var then = new Date().getTime(); for (let now = then; now - then < ms; now = new Date().getTime()) { - liberator.threadYield(); + threadYield(); if ((now - then) % 1000 < 10) - liberator.dump("waited: " + (now - then) + " ms"); + dump("waited: " + (now - then) + " ms"); - if (!liberator.events.feedingKeys) + if (!events.feedingKeys) return false; - if (liberator.buffer.loaded > 0) + if (buffer.loaded > 0) { - liberator.sleep(250); + sleep(250); break; } else - liberator.echo("Waiting for page to load..."); + echo("Waiting for page to load..."); } - liberator.modes.show(); + modes.show(); // TODO: allow macros to be continued when page does not fully load with an option - var ret = (liberator.buffer.loaded == 1); + var ret = (buffer.loaded == 1); if (!ret) - liberator.echoerr("Page did not load completely in " + ms + " milliseconds. Macro stopped."); - liberator.dump("done waiting: " + ret); + echoerr("Page did not load completely in " + ms + " milliseconds. Macro stopped."); + dump("done waiting: " + ret); // sometimes the input widget had focus when replaying a macro // maybe this call should be moved somewhere else? - // liberator.focusContent(true); + // focusContent(true); return ret; } // load all macros inside ~/.vimperator/macros/ - // setTimeout needed since liberator.io. is loaded after liberator.events. + // setTimeout needed since io. is loaded after events. setTimeout (function () { // FIXME: largely duplicated for loading plugins try { - let dirs = liberator.io.getRuntimeDirectories("macros"); + let dirs = io.getRuntimeDirectories("macros"); if (dirs.length > 0) { for (let [,dir] in Iterator(dirs)) { - liberator.echomsg("Searching for \"macros/*\" in \"" + dir.path + "\"", 2); + echomsg("Searching for \"macros/*\" in \"" + dir.path + "\"", 2); - liberator.log("Sourcing macros directory: " + dir.path + "...", 3); + log("Sourcing macros directory: " + dir.path + "...", 3); - let files = liberator.io.readDirectory(dir.path); + let files = io.readDirectory(dir.path); files.forEach(function (file) { if (!file.exists() || file.isDirectory() || @@ -622,21 +617,21 @@ liberator.Events = function () //{{{ return; let name = file.leafName.replace(/\.vimp$/i, ""); - macros.set(name, liberator.io.readFile(file).split("\n")[0]); + macros.set(name, io.readFile(file).split("\n")[0]); - liberator.log("Macro " + name + " added: " + macros.get(name), 5); + log("Macro " + name + " added: " + macros.get(name), 5); }); } } else { - liberator.log("No user macros directory found", 3); + log("No user macros directory found", 3); } } catch (e) { // thrown if directory does not exist - liberator.log("Error sourcing macros directory: " + e, 9); + log("Error sourcing macros directory: " + e, 9); } }, 100); @@ -644,86 +639,86 @@ liberator.Events = function () //{{{ ////////////////////// MAPPINGS //////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ - liberator.mappings.add(liberator.modes.all, + mappings.add(modes.all, ["", ""], "Focus content", - function () { liberator.events.onEscape(); }); + function () { events.onEscape(); }); // add the ":" mapping in all but insert mode mappings - liberator.mappings.add([liberator.modes.NORMAL, liberator.modes.VISUAL, liberator.modes.HINTS, liberator.modes.MESSAGE, liberator.modes.COMPOSE, liberator.modes.CARET, liberator.modes.TEXTAREA], + mappings.add([modes.NORMAL, modes.VISUAL, modes.HINTS, modes.MESSAGE, modes.COMPOSE, modes.CARET, modes.TEXTAREA], [":"], "Enter command line mode", - function () { liberator.commandline.open(":", "", liberator.modes.EX); }); + function () { commandline.open(":", "", modes.EX); }); // focus events - liberator.mappings.add([liberator.modes.NORMAL, liberator.modes.VISUAL, liberator.modes.CARET], + mappings.add([modes.NORMAL, modes.VISUAL, modes.CARET], [""], "Advance keyboard focus", function () { document.commandDispatcher.advanceFocus(); }); - liberator.mappings.add([liberator.modes.NORMAL, liberator.modes.VISUAL, liberator.modes.CARET, liberator.modes.INSERT, liberator.modes.TEXTAREA], + mappings.add([modes.NORMAL, modes.VISUAL, modes.CARET, modes.INSERT, modes.TEXTAREA], [""], "Rewind keyboard focus", function () { document.commandDispatcher.rewindFocus(); }); - liberator.mappings.add(liberator.modes.all, - [""], "Temporarily ignore all " + liberator.config.name + " key bindings", - function () { liberator.modes.passAllKeys = true; }); + mappings.add(modes.all, + [""], "Temporarily ignore all " + config.name + " key bindings", + function () { modes.passAllKeys = true; }); - liberator.mappings.add(liberator.modes.all, + mappings.add(modes.all, [""], "Pass through next key", - function () { liberator.modes.passNextKey = true; }); + function () { modes.passNextKey = true; }); - liberator.mappings.add(liberator.modes.all, + mappings.add(modes.all, [""], "Do nothing", function () { return; }); // macros - liberator.mappings.add([liberator.modes.NORMAL, liberator.modes.MESSAGE], + mappings.add([modes.NORMAL, modes.MESSAGE], ["q"], "Record a key sequence into a macro", - function (arg) { liberator.events.startRecording(arg); }, - { flags: liberator.Mappings.flags.ARGUMENT }); + function (arg) { events.startRecording(arg); }, + { flags: Mappings.flags.ARGUMENT }); - liberator.mappings.add([liberator.modes.NORMAL, liberator.modes.MESSAGE], + mappings.add([modes.NORMAL, modes.MESSAGE], ["@"], "Play a macro", function (count, arg) { if (count < 1) count = 1; - while (count-- && liberator.events.playMacro(arg)) + while (count-- && events.playMacro(arg)) ; }, - { flags: liberator.Mappings.flags.ARGUMENT | liberator.Mappings.flags.COUNT }); + { flags: Mappings.flags.ARGUMENT | Mappings.flags.COUNT }); /////////////////////////////////////////////////////////////////////////////}}} ////////////////////// COMMANDS //////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ - liberator.commands.add(["delmac[ros]"], + commands.add(["delmac[ros]"], "Delete macros", function (args, special) { if (special) args = ".*"; // XXX - liberator.events.deleteMacros(args); + events.deleteMacros(args); }, { bang: true, - completer: function (filter) liberator.completion.macro(filter) + completer: function (filter) completion.macro(filter) }); - liberator.commands.add(["macros"], + commands.add(["macros"], "List all macros", function (args) { XML.prettyPrinting = false; - var str = liberator.template.tabular(["Macro", "Keys"], [], liberator.events.getMacros(args)); - liberator.echo(str, liberator.commandline.FORCE_MULTILINE); + var str = template.tabular(["Macro", "Keys"], [], events.getMacros(args)); + echo(str, commandline.FORCE_MULTILINE); }, - { completer: function (filter) liberator.completion.macro(filter) }); + { completer: function (filter) completion.macro(filter) }); - liberator.commands.add(["pl[ay]"], + commands.add(["pl[ay]"], "Replay a recorded macro", - function (args) { liberator.events.playMacro(args.arguments[0]); }, + function (args) { events.playMacro(args.arguments[0]); }, { argCount: "1", - completer: function (filter) liberator.completion.macro(filter) + completer: function (filter) completion.macro(filter) }); /////////////////////////////////////////////////////////////////////////////}}} @@ -739,7 +734,7 @@ liberator.Events = function () //{{{ destroy: function () { // removeEventListeners() to avoid mem leaks - liberator.dump("TODO: remove all eventlisteners"); + dump("TODO: remove all eventlisteners"); if (typeof getBrowser != "undefined") getBrowser().removeProgressListener(this.progressListener); @@ -758,11 +753,11 @@ liberator.Events = function () //{{{ if (!/[a-zA-Z0-9]/.test(macro)) { // TODO: ignore this like Vim? - liberator.echoerr("E354: Invalid register name: '" + macro + "'"); + echoerr("E354: Invalid register name: '" + macro + "'"); return; } - liberator.modes.isRecording = true; + modes.isRecording = true; if (/[A-Z]/.test(macro)) // uppercase (append) { @@ -782,7 +777,7 @@ liberator.Events = function () //{{{ var res = false; if (!/[a-zA-Z0-9@]/.test(macro) && macro.length == 1) { - liberator.echoerr("E354: Invalid register name: '" + macro + "'"); + echoerr("E354: Invalid register name: '" + macro + "'"); return false; } @@ -790,7 +785,7 @@ liberator.Events = function () //{{{ { if (!lastMacro) { - liberator.echoerr("E748: No previously used register"); + echoerr("E748: No previously used register"); return false; } } @@ -811,18 +806,18 @@ liberator.Events = function () //{{{ } catch (e) {} - liberator.buffer.loaded = 1; // even if not a full page load, assume it did load correctly before starting the macro - liberator.modes.isReplaying = true; - res = liberator.events.feedkeys(macros.get(lastMacro), true); // true -> noremap - liberator.modes.isReplaying = false; + buffer.loaded = 1; // even if not a full page load, assume it did load correctly before starting the macro + modes.isReplaying = true; + res = events.feedkeys(macros.get(lastMacro), true); // true -> noremap + modes.isReplaying = false; } else { if (lastMacro.length == 1) // TODO: ignore this like Vim? - liberator.echoerr("Exxx: Register " + lastMacro + " not set"); + echoerr("Exxx: Register " + lastMacro + " not set"); else - liberator.echoerr("Exxx: Named macro '" + lastMacro + "' not set"); + echoerr("Exxx: Named macro '" + lastMacro + "' not set"); } return res; }, @@ -923,10 +918,10 @@ liberator.Events = function () //{{{ if (!this.feedingKeys) break; // stop feeding keys if page loading failed - if (liberator.modes.isReplaying && !waitForPageLoaded()) + if (modes.isReplaying && !waitForPageLoaded()) break; // else // a short break between keys often helps - // liberator.sleep(50); + // sleep(50); } this.feedingKeys = wasFeeding; return i == keys.length; @@ -1029,7 +1024,7 @@ liberator.Events = function () //{{{ onFocusChange: function (event) { // command line has it's own focus change handler - if (liberator.mode == liberator.modes.COMMAND_LINE) + if (mode == modes.COMMAND_LINE) return; var win = window.document.commandDispatcher.focusedWindow; @@ -1037,9 +1032,9 @@ liberator.Events = function () //{{{ if (elem && elem.readOnly) return; - //liberator.log("onFocusChange: " + elem); - //liberator.dump("=+++++++++=\n" + liberator.util.objectToString(event.target) + "\n") - //liberator.dump (elem + ": " + win + "\n");//" - target: " + event.target + " - origtarget: " + event.originalTarget + " - expltarget: " + event.explicitOriginalTarget + "\n"); + //log("onFocusChange: " + elem); + //dump("=+++++++++=\n" + util.objectToString(event.target) + "\n") + //dump (elem + ": " + win + "\n");//" - target: " + event.target + " - origtarget: " + event.originalTarget + " - expltarget: " + event.explicitOriginalTarget + "\n"); if (elem && ( (elem instanceof HTMLInputElement && (elem.type.toLowerCase() == "text" || elem.type.toLowerCase() == "password")) || @@ -1048,53 +1043,53 @@ liberator.Events = function () //{{{ { this.wantsModeReset = false; liberator.mode = liberator.modes.INSERT; - liberator.buffer.lastInputField = elem; + buffer.lastInputField = elem; return; } if (elem && elem instanceof HTMLTextAreaElement) { this.wantsModeReset = false; - if (liberator.options["insertmode"]) - liberator.modes.set(liberator.modes.INSERT, liberator.modes.TEXTAREA); + if (options["insertmode"]) + modes.set(modes.INSERT, modes.TEXTAREA); else if (elem.selectionEnd - elem.selectionStart > 0) - liberator.modes.set(liberator.modes.VISUAL, liberator.modes.TEXTAREA); + modes.set(modes.VISUAL, modes.TEXTAREA); else - liberator.modes.main = liberator.modes.TEXTAREA; - liberator.buffer.lastInputField = elem; + modes.main = modes.TEXTAREA; + buffer.lastInputField = elem; return; } - if (liberator.config.name == "Muttator") + if (config.name == "Muttator") { // we switch to -- MESSAGE -- mode for muttator, when the main HTML widget gets focus if ((win && win.document && win.document instanceof HTMLDocument) || elem instanceof HTMLAnchorElement) { - if (liberator.config.isComposeWindow) + if (config.isComposeWindow) { - liberator.dump("Compose editor got focus"); - liberator.modes.set(liberator.modes.INSERT, liberator.modes.TEXTAREA); + dump("Compose editor got focus"); + modes.set(modes.INSERT, modes.TEXTAREA); } - else if (liberator.mode != liberator.modes.MESSAGE) + else if (mode != modes.MESSAGE) liberator.mode = liberator.modes.MESSAGE; return; } } - if (liberator.mode == liberator.modes.INSERT || - liberator.mode == liberator.modes.TEXTAREA || - liberator.mode == liberator.modes.MESSAGE || - liberator.mode == liberator.modes.VISUAL) + if (mode == modes.INSERT || + mode == modes.TEXTAREA || + mode == modes.MESSAGE || + mode == modes.VISUAL) { // FIXME: currently this hack is disabled to make macros work // this.wantsModeReset = true; // setTimeout(function () { - // liberator.dump("cur: " + liberator.mode + "\n"); - // if (liberator.events.wantsModeReset) + // dump("cur: " + mode + "\n"); + // if (events.wantsModeReset) // { - // liberator.events.wantsModeReset = false; - liberator.modes.reset(); + // events.wantsModeReset = false; + modes.reset(); // } // }, 0); } @@ -1107,22 +1102,22 @@ liberator.Events = function () //{{{ if (controller && controller.isCommandEnabled("cmd_copy")) couldCopy = true; - if (liberator.mode != liberator.modes.VISUAL) + if (mode != modes.VISUAL) { if (couldCopy) { - if ((liberator.mode == liberator.modes.TEXTAREA || - (liberator.modes.extended & liberator.modes.TEXTAREA)) - && !liberator.options["insertmode"]) - liberator.modes.set(liberator.modes.VISUAL, liberator.modes.TEXTAREA); - else if (liberator.mode == liberator.modes.CARET) - liberator.modes.set(liberator.modes.VISUAL, liberator.modes.CARET); + if ((mode == modes.TEXTAREA || + (modes.extended & modes.TEXTAREA)) + && !options["insertmode"]) + modes.set(modes.VISUAL, modes.TEXTAREA); + else if (mode == modes.CARET) + modes.set(modes.VISUAL, modes.CARET); } } // XXX: disabled, as i think automatically starting visual caret mode does more harm than help // else // { - // if (!couldCopy && liberator.modes.extended & liberator.modes.CARET) + // if (!couldCopy && modes.extended & modes.CARET) // liberator.mode = liberator.modes.CARET; // } }, @@ -1130,17 +1125,17 @@ liberator.Events = function () //{{{ // global escape handler, is called in ALL modes onEscape: function () { - if (!liberator.modes.passNextKey) + if (!modes.passNextKey) { - if (liberator.modes.passAllKeys) + if (modes.passAllKeys) { - liberator.modes.passAllKeys = false; + modes.passAllKeys = false; return; } - switch (liberator.mode) + switch (mode) { - case liberator.modes.NORMAL: + case modes.NORMAL: // clear any selection made var selection = window.content.getSelection(); try @@ -1148,39 +1143,39 @@ liberator.Events = function () //{{{ selection.collapseToStart(); } catch (e) {} - liberator.commandline.clear(); + commandline.clear(); - liberator.modes.reset(); - liberator.focusContent(true); + modes.reset(); + focusContent(true); break; - case liberator.modes.VISUAL: - if (liberator.modes.extended & liberator.modes.TEXTAREA) + case modes.VISUAL: + if (modes.extended & modes.TEXTAREA) liberator.mode = liberator.modes.TEXTAREA; - else if (liberator.modes.extended & liberator.modes.CARET) + else if (modes.extended & modes.CARET) liberator.mode = liberator.modes.CARET; break; - case liberator.modes.CARET: + case modes.CARET: // setting this option will trigger an observer which will // care about all other details like setting the NORMAL mode - liberator.options.setPref("accessibility.browsewithcaret", false); + options.setPref("accessibility.browsewithcaret", false); break; - case liberator.modes.INSERT: - if ((liberator.modes.extended & liberator.modes.TEXTAREA) && !liberator.options["insertmode"]) + case modes.INSERT: + if ((modes.extended & modes.TEXTAREA) && !options["insertmode"]) { liberator.mode = liberator.modes.TEXTAREA; } else { - liberator.modes.reset(); - liberator.focusContent(true); + modes.reset(); + focusContent(true); } break; default: // HINTS, CUSTOM or COMMAND_LINE - liberator.modes.reset(); + modes.reset(); break; } } @@ -1190,26 +1185,26 @@ liberator.Events = function () //{{{ // the commandline has focus onKeyPress: function (event) { - var key = liberator.events.toString(event); + var key = events.toString(event); if (!key) return true; - //liberator.log(key + " in mode: " + liberator.mode); - //liberator.dump(key + " in mode: " + liberator.mode + "\n"); + //log(key + " in mode: " + mode); + //dump(key + " in mode: " + mode + "\n"); - if (liberator.modes.isRecording) + if (modes.isRecording) { if (key == "q") // TODO: should not be hardcoded { - liberator.modes.isRecording = false; - liberator.log("Recorded " + currentMacro + ": " + macros.get(currentMacro), 9); - liberator.echo("Recorded macro '" + currentMacro + "'"); + modes.isRecording = false; + log("Recorded " + currentMacro + ": " + macros.get(currentMacro), 9); + echo("Recorded macro '" + currentMacro + "'"); event.preventDefault(); event.stopPropagation(); return true; } - else if (!(liberator.modes.extended & liberator.modes.INACTIVE_HINT) && - !liberator.mappings.hasMap(liberator.mode, liberator.input.buffer + key)) + else if (!(modes.extended & modes.INACTIVE_HINT) && + !mappings.hasMap(mode, input.buffer + key)) { macros.set(currentMacro, macros.get(currentMacro) + key); } @@ -1222,12 +1217,12 @@ liberator.Events = function () //{{{ // we can differentiate between a recorded // interrupting whatever it's started and a real // interrupting our playback. - if (liberator.events.feedingKeys) + if (events.feedingKeys) { if (key == "" && !event.isMacro) { - liberator.events.feedingKeys = false; - setTimeout(function () { liberator.echo("Canceled playback of macro '" + lastMacro + "'") }, 100); + events.feedingKeys = false; + setTimeout(function () { echo("Canceled playback of macro '" + lastMacro + "'") }, 100); event.preventDefault(); event.stopPropagation(); return true; @@ -1237,24 +1232,24 @@ liberator.Events = function () //{{{ var stop = true; // set to false if we should NOT consume this event but let Firefox handle it var win = document.commandDispatcher.focusedWindow; - if (win && win.document.designMode == "on" && !liberator.config.isComposeWindow) + if (win && win.document.designMode == "on" && !config.isComposeWindow) return false; // menus have their own command handlers - if (liberator.modes.extended & liberator.modes.MENU) + if (modes.extended & modes.MENU) return false; // handle Escape-one-key mode (Ctrl-v) - if (liberator.modes.passNextKey && !liberator.modes.passAllKeys) + if (modes.passNextKey && !modes.passAllKeys) { - liberator.modes.passNextKey = false; + modes.passNextKey = false; return false; } // handle Escape-all-keys mode (Ctrl-q) - if (liberator.modes.passAllKeys) + if (modes.passAllKeys) { - if (liberator.modes.passNextKey) - liberator.modes.passNextKey = false; // and then let flow continue + if (modes.passNextKey) + modes.passNextKey = false; // and then let flow continue else if (key == "" || key == "" || key == "") ; // let flow continue to handle these keys to cancel escape-all-keys mode else @@ -1262,10 +1257,10 @@ liberator.Events = function () //{{{ } // just forward event without checking any mappings when the MOW is open - if (liberator.mode == liberator.modes.COMMAND_LINE && - (liberator.modes.extended & liberator.modes.OUTPUT_MULTILINE)) + if (mode == modes.COMMAND_LINE && + (modes.extended & modes.OUTPUT_MULTILINE)) { - liberator.commandline.onMultilineOutputEvent(event); + commandline.onMultilineOutputEvent(event); event.preventDefault(); event.stopPropagation(); return false; @@ -1274,8 +1269,8 @@ liberator.Events = function () //{{{ // XXX: ugly hack for now pass certain keys to firefox as they are without beeping // also fixes key navigation in combo boxes, submitting forms, etc. // FIXME: breaks iabbr for now --mst - if ((liberator.config.name == "Vimperator" && liberator.mode == liberator.modes.NORMAL) - || liberator.mode == liberator.modes.INSERT) + if ((config.name == "Vimperator" && mode == modes.NORMAL) + || mode == modes.INSERT) { if (key == "") return false; @@ -1306,17 +1301,17 @@ liberator.Events = function () //{{{ if (key != "" && key != "") { // custom mode... - if (liberator.mode == liberator.modes.CUSTOM) + if (mode == modes.CUSTOM) { - liberator.plugins.onEvent(event); + plugins.onEvent(event); event.preventDefault(); event.stopPropagation(); return false; } // if Hint mode is on, special handling of keys is required - if (liberator.mode == liberator.modes.HINTS) + if (mode == modes.HINTS) { - liberator.hints.onEvent(event); + hints.onEvent(event); event.preventDefault(); event.stopPropagation(); return false; @@ -1330,102 +1325,102 @@ liberator.Events = function () //{{{ // whatever reason). if that happens to be correct, well.. // XXX: why not just do that as well for HINTS mode actually? - if (liberator.mode == liberator.modes.CUSTOM) + if (mode == modes.CUSTOM) return true; - var countStr = liberator.input.buffer.match(/^[0-9]*/)[0]; - var candidateCommand = (liberator.input.buffer + key).replace(countStr, ""); + var countStr = input.buffer.match(/^[0-9]*/)[0]; + var candidateCommand = (input.buffer + key).replace(countStr, ""); var map; if (event.noremap) - map = liberator.mappings.getDefault(liberator.mode, candidateCommand); + map = mappings.getDefault(mode, candidateCommand); else - map = liberator.mappings.get(liberator.mode, candidateCommand); + map = mappings.get(mode, candidateCommand); // counts must be at the start of a complete mapping (10j -> go 10 lines down) - if (/^[1-9][0-9]*$/.test(liberator.input.buffer + key)) + if (/^[1-9][0-9]*$/.test(input.buffer + key)) { // no count for insert mode mappings - if (liberator.mode == liberator.modes.INSERT || liberator.mode == liberator.modes.COMMAND_LINE) + if (mode == modes.INSERT || mode == modes.COMMAND_LINE) stop = false; else { - liberator.input.buffer += key; + input.buffer += key; inputBufferLength++; } } - else if (liberator.input.pendingArgMap) + else if (input.pendingArgMap) { - liberator.input.buffer = ""; + input.buffer = ""; inputBufferLength = 0; - var tmp = liberator.input.pendingArgMap; // must be set to null before .execute; if not - liberator.input.pendingArgMap = null; // v.input.pendingArgMap is still 'true' also for new feeded keys + var tmp = input.pendingArgMap; // must be set to null before .execute; if not + input.pendingArgMap = null; // v.input.pendingArgMap is still 'true' also for new feeded keys if (key != "" && key != "") { - if (liberator.modes.isReplaying && !waitForPageLoaded()) + if (modes.isReplaying && !waitForPageLoaded()) return true; - tmp.execute(null, liberator.input.count, key); + tmp.execute(null, input.count, key); } } // only follow a map if there isn't a longer possible mapping // (allows you to do :map z yy, when zz is a longer mapping than z) // TODO: map.rhs is only defined for user defined commands, should add a "isDefault" property else if (map && !skipMap && (map.rhs || - liberator.mappings.getCandidates(liberator.mode, candidateCommand).length == 0)) + mappings.getCandidates(mode, candidateCommand).length == 0)) { - liberator.input.count = parseInt(countStr, 10); - if (isNaN(liberator.input.count)) - liberator.input.count = -1; - if (map.flags & liberator.Mappings.flags.ARGUMENT) + input.count = parseInt(countStr, 10); + if (isNaN(input.count)) + input.count = -1; + if (map.flags & Mappings.flags.ARGUMENT) { - liberator.input.pendingArgMap = map; - liberator.input.buffer += key; + input.pendingArgMap = map; + input.buffer += key; inputBufferLength++; } - else if (liberator.input.pendingMotionMap) + else if (input.pendingMotionMap) { if (key != "" && key != "") { - liberator.input.pendingMotionMap.execute(candidateCommand, liberator.input.count, null); + input.pendingMotionMap.execute(candidateCommand, input.count, null); } - liberator.input.pendingMotionMap = null; - liberator.input.buffer = ""; + input.pendingMotionMap = null; + input.buffer = ""; inputBufferLength = 0; } // no count support for these commands yet - else if (map.flags & liberator.Mappings.flags.MOTION) + else if (map.flags & Mappings.flags.MOTION) { - liberator.input.pendingMotionMap = map; - liberator.input.buffer = ""; + input.pendingMotionMap = map; + input.buffer = ""; inputBufferLength = 0; } else { - liberator.input.buffer = ""; + input.buffer = ""; inputBufferLength = 0; - if (liberator.modes.isReplaying && !waitForPageLoaded()) + if (modes.isReplaying && !waitForPageLoaded()) return true; - var ret = map.execute(null, liberator.input.count); - if (map.flags & liberator.Mappings.flags.ALLOW_EVENT_ROUTING && ret) + var ret = map.execute(null, input.count); + if (map.flags & Mappings.flags.ALLOW_EVENT_ROUTING && ret) stop = false; } } - else if (liberator.mappings.getCandidates(liberator.mode, candidateCommand).length > 0 && !skipMap) + else if (mappings.getCandidates(mode, candidateCommand).length > 0 && !skipMap) { - liberator.input.buffer += key; + input.buffer += key; inputBufferLength++; } else // if the key is neither a mapping nor the start of one { // the mode checking is necessary so that things like g do not beep - if (liberator.input.buffer != "" && !skipMap && (liberator.mode == liberator.modes.INSERT || - liberator.mode == liberator.modes.COMMAND_LINE || liberator.mode == liberator.modes.TEXTAREA)) + if (input.buffer != "" && !skipMap && (mode == modes.INSERT || + mode == modes.COMMAND_LINE || mode == modes.TEXTAREA)) { // no map found -> refeed stuff in v.input.buffer (only while in INSERT, CO... modes) skipMap = true; // ignore maps while doing so - liberator.events.feedkeys(liberator.input.buffer, true); + events.feedkeys(input.buffer, true); } if (skipMap) { @@ -1433,23 +1428,23 @@ liberator.Events = function () //{{{ skipMap = false; // done... } - liberator.input.buffer = ""; - liberator.input.pendingArgMap = null; - liberator.input.pendingMotionMap = null; + input.buffer = ""; + input.pendingArgMap = null; + input.pendingMotionMap = null; if (key != "" && key != "") { // allow key to be passed to firefox if we can't handle it stop = false; - if (liberator.mode == liberator.modes.COMMAND_LINE) + if (mode == modes.COMMAND_LINE) { - if (!(liberator.modes.extended & liberator.modes.INPUT_MULTILINE)) - liberator.commandline.onEvent(event); // reroute event in command line mode + if (!(modes.extended & modes.INPUT_MULTILINE)) + commandline.onEvent(event); // reroute event in command line mode } - else if (liberator.mode != liberator.modes.INSERT && liberator.mode != liberator.modes.TEXTAREA) + else if (mode != modes.INSERT && mode != modes.TEXTAREA) { - liberator.beep(); + beep(); } } } @@ -1460,15 +1455,15 @@ liberator.Events = function () //{{{ event.stopPropagation(); } - var motionMap = (liberator.input.pendingMotionMap && liberator.input.pendingMotionMap.names[0]) || ""; - liberator.statusline.updateInputBuffer(motionMap + liberator.input.buffer); + var motionMap = (input.pendingMotionMap && input.pendingMotionMap.names[0]) || ""; + statusline.updateInputBuffer(motionMap + input.buffer); return false; }, // this is need for sites like msn.com which focus the input field on keydown onKeyUpOrDown: function (event) { - if (liberator.modes.passNextKey ^ liberator.modes.passAllKeys || isFormElemFocused()) + if (modes.passNextKey ^ modes.passAllKeys || isFormElemFocused()) return true; event.stopPropagation(); @@ -1499,23 +1494,23 @@ liberator.Events = function () //{{{ // only thrown for the current tab, not when another tab changes if (flags & Components.interfaces.nsIWebProgressListener.STATE_START) { - liberator.buffer.loaded = 0; - liberator.statusline.updateProgress(0); + buffer.loaded = 0; + statusline.updateProgress(0); - liberator.autocommands.trigger("PageLoadPre", {url: liberator.buffer.URL}); + autocommands.trigger("PageLoadPre", {url: buffer.URL}); // don't reset mode if a frame of the frameset gets reloaded which // is not the focused frame if (document.commandDispatcher.focusedWindow == webProgress.DOMWindow) { - setTimeout(function () { liberator.modes.reset(false); }, - liberator.mode == liberator.modes.HINTS ? 500 : 0); + setTimeout(function () { modes.reset(false); }, + mode == modes.HINTS ? 500 : 0); } } else if (flags & Components.interfaces.nsIWebProgressListener.STATE_STOP) { - liberator.buffer.loaded = (status == 0 ? 1 : 2); - liberator.statusline.updateUrl(); + buffer.loaded = (status == 0 ? 1 : 2); + statusline.updateUrl(); } } }, @@ -1524,53 +1519,53 @@ liberator.Events = function () //{{{ { const nsIWebProgressListener = Components.interfaces.nsIWebProgressListener; if (aState & nsIWebProgressListener.STATE_IS_INSECURE) - liberator.statusline.setClass("insecure"); + statusline.setClass("insecure"); else if (aState & nsIWebProgressListener.STATE_IS_BROKEN) - liberator.statusline.setClass("broken"); + statusline.setClass("broken"); else if (aState & nsIWebProgressListener.STATE_IS_SECURE) - liberator.statusline.setClass("secure"); + statusline.setClass("secure"); }, onStatusChange: function (webProgress, request, status, message) { - liberator.statusline.updateUrl(message); + statusline.updateUrl(message); }, onProgressChange: function (webProgress, request, curSelfProgress, maxSelfProgress, curTotalProgress, maxTotalProgress) { - liberator.statusline.updateProgress(curTotalProgress/maxTotalProgress); + statusline.updateProgress(curTotalProgress/maxTotalProgress); }, // happens when the users switches tabs onLocationChange: function () { - liberator.statusline.updateUrl(); - liberator.statusline.updateProgress(); + statusline.updateUrl(); + statusline.updateProgress(); - liberator.autocommands.trigger("LocationChange", {url: liberator.buffer.URL}); + autocommands.trigger("LocationChange", {url: buffer.URL}); // if this is not delayed we get the position of the old buffer - setTimeout(function () { liberator.statusline.updateBufferPosition(); }, 100); + setTimeout(function () { statusline.updateBufferPosition(); }, 100); }, // called at the very end of a page load asyncUpdateUI: function () { - setTimeout(liberator.statusline.updateUrl, 100); + setTimeout(statusline.updateUrl, 100); }, setOverLink : function (link, b) { - var ssli = liberator.options["showstatuslinks"]; + var ssli = options["showstatuslinks"]; if (link && ssli) { if (ssli == 1) - liberator.statusline.updateUrl("Link: " + link); + statusline.updateUrl("Link: " + link); else if (ssli == 2) - liberator.echo("Link: " + link, liberator.commandline.DISALLOW_MULTILINE); + echo("Link: " + link, commandline.DISALLOW_MULTILINE); } if (link == "") { if (ssli == 1) - liberator.statusline.updateUrl(); + statusline.updateUrl(); else if (ssli == 2) - liberator.modes.show(); + modes.show(); } }, @@ -1608,7 +1603,7 @@ liberator.Events = function () //{{{ switch (aData) { case "accessibility.browsewithcaret": - var value = liberator.options.getPref("accessibility.browsewithcaret", false); + var value = options.getPref("accessibility.browsewithcaret", false); liberator.mode = value ? liberator.modes.CARET : liberator.modes.NORMAL; break; } @@ -1630,7 +1625,7 @@ liberator.Events = function () //{{{ catch (e) {} eventManager.prefObserver.register(); - liberator.registerObserver("shutdown", function () { + registerObserver("shutdown", function () { eventManager.destroy(); eventManager.prefObserver.unregister(); }); diff --git a/content/find.js b/content/find.js index 501f371b..9bb6a751 100644 --- a/content/find.js +++ b/content/find.js @@ -37,7 +37,7 @@ the terms of any one of the MPL, the GPL or the LGPL. // : incremental searches shouldn't permanently update search modifiers // make sure you only create this object when the "liberator" object is ready -liberator.Search = function () //{{{ +with (liberator) liberator.Search = function () //{{{ { //////////////////////////////////////////////////////////////////////////////// ////////////////////// PRIVATE SECTION ///////////////////////////////////////// @@ -56,13 +56,13 @@ liberator.Search = function () //{{{ var linksOnly = false; // search is limited to link text only // Event handlers for search - closure is needed - liberator.registerCallback("change", liberator.modes.SEARCH_FORWARD, function (command) { liberator.search.searchKeyPressed(command); }); - liberator.registerCallback("submit", liberator.modes.SEARCH_FORWARD, function (command) { liberator.search.searchSubmitted(command); }); - liberator.registerCallback("cancel", liberator.modes.SEARCH_FORWARD, function () { liberator.search.searchCanceled(); }); - // TODO: allow advanced modes in register/triggerCallback - liberator.registerCallback("change", liberator.modes.SEARCH_BACKWARD, function (command) { liberator.search.searchKeyPressed(command); }); - liberator.registerCallback("submit", liberator.modes.SEARCH_BACKWARD, function (command) { liberator.search.searchSubmitted(command); }); - liberator.registerCallback("cancel", liberator.modes.SEARCH_BACKWARD, function () { liberator.search.searchCanceled(); }); + registerCallback("change", modes.SEARCH_FORWARD, function (command) { search.searchKeyPressed(command); }); + registerCallback("submit", modes.SEARCH_FORWARD, function (command) { search.searchSubmitted(command); }); + registerCallback("cancel", modes.SEARCH_FORWARD, function () { search.searchCanceled(); }); + // TODO: allow advanced myModes in register/triggerCallback + registerCallback("change", modes.SEARCH_BACKWARD, function (command) { search.searchKeyPressed(command); }); + registerCallback("submit", modes.SEARCH_BACKWARD, function (command) { search.searchSubmitted(command); }); + registerCallback("cancel", modes.SEARCH_BACKWARD, function () { search.searchCanceled(); }); // set searchString, searchPattern, caseSensitive, linksOnly function processUserPattern(pattern) @@ -80,7 +80,7 @@ liberator.Search = function () //{{{ linksOnly = true; else if (/\L/.test(pattern)) linksOnly = false; - else if (liberator.options["linksearch"]) + else if (options["linksearch"]) linksOnly = true; else linksOnly = false; @@ -93,9 +93,9 @@ liberator.Search = function () //{{{ caseSensitive = false; else if (/\C/.test(pattern)) caseSensitive = true; - else if (liberator.options["ignorecase"] && liberator.options["smartcase"] && /[A-Z]/.test(pattern)) + else if (options["ignorecase"] && options["smartcase"] && /[A-Z]/.test(pattern)) caseSensitive = true; - else if (liberator.options["ignorecase"]) + else if (options["ignorecase"]) caseSensitive = false; else caseSensitive = true; @@ -177,7 +177,7 @@ liberator.Search = function () //{{{ } var baseNode = - baseNode = liberator.util.xmlToDom(baseNode, window.content.document); + baseNode = util.xmlToDom(baseNode, window.content.document); var body = doc.body; var count = body.childNodes.length; @@ -204,8 +204,8 @@ liberator.Search = function () //{{{ this.startPt.setStart(node, node.childNodes.length); this.startPt.setEnd(node, node.childNodes.length); if (n++ % 20 == 0) - liberator.threadYield(); - if (liberator.interrupted) + threadYield(); + if (interrupted) break; } }, @@ -228,34 +228,34 @@ liberator.Search = function () //{{{ ////////////////////// OPTIONS ///////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ - liberator.options.add(["hlsearch", "hls"], + options.add(["hlsearch", "hls"], "Highlight previous search pattern matches", "boolean", "false", { setter: function (value) { if (value) - liberator.search.highlight(); + search.highlight(); else - liberator.search.clear(); + search.clear(); return value; } }); - liberator.options.add(["ignorecase", "ic"], + options.add(["ignorecase", "ic"], "Ignore case in search patterns", "boolean", true); - liberator.options.add(["incsearch", "is"], + options.add(["incsearch", "is"], "Show where the search pattern matches as it is typed", "boolean", true); - liberator.options.add(["linksearch", "lks"], + options.add(["linksearch", "lks"], "Limit the search to hyperlink text", "boolean", false); - liberator.options.add(["smartcase", "scs"], + options.add(["smartcase", "scs"], "Override the 'ignorecase' option if the pattern contains uppercase characters", "boolean", true); @@ -263,48 +263,48 @@ liberator.Search = function () //{{{ ////////////////////// MAPPINGS //////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ - var modes = liberator.config.browserModes || [liberator.modes.NORMAL]; - modes = modes.concat([liberator.modes.CARET]); + var myModes = config.browserModes || [modes.NORMAL]; + myModes = myModes.concat([modes.CARET]); - liberator.mappings.add(modes, + mappings.add(myModes, ["/"], "Search forward for a pattern", - function () { liberator.search.openSearchDialog(liberator.modes.SEARCH_FORWARD); }); + function () { search.openSearchDialog(modes.SEARCH_FORWARD); }); - liberator.mappings.add(modes, + mappings.add(myModes, ["?"], "Search backwards for a pattern", - function () { liberator.search.openSearchDialog(liberator.modes.SEARCH_BACKWARD); }); + function () { search.openSearchDialog(modes.SEARCH_BACKWARD); }); - liberator.mappings.add(modes, + mappings.add(myModes, ["n"], "Find next", - function () { liberator.search.findAgain(false); }); + function () { search.findAgain(false); }); - liberator.mappings.add(modes, + mappings.add(myModes, ["N"], "Find previous", - function () { liberator.search.findAgain(true); }); + function () { search.findAgain(true); }); - liberator.mappings.add(modes.concat([liberator.modes.CARET, liberator.modes.TEXTAREA]), ["*"], + mappings.add(myModes.concat([modes.CARET, modes.TEXTAREA]), ["*"], "Find word under cursor", function () { - liberator.search.searchSubmitted(liberator.buffer.getCurrentWord(), false); - liberator.search.findAgain(); + search.searchSubmitted(buffer.getCurrentWord(), false); + search.findAgain(); }); - liberator.mappings.add(modes.concat([liberator.modes.CARET, liberator.modes.TEXTAREA]), ["#"], + mappings.add(myModes.concat([modes.CARET, modes.TEXTAREA]), ["#"], "Find word under cursor backwards", function () { - liberator.search.searchSubmitted(liberator.buffer.getCurrentWord(), true); - liberator.search.findAgain(); + search.searchSubmitted(buffer.getCurrentWord(), true); + search.findAgain(); }); /////////////////////////////////////////////////////////////////////////////}}} ////////////////////// COMMANDS //////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ - liberator.commands.add(["noh[lsearch]"], + commands.add(["noh[lsearch]"], "Remove the search highlighting", - function () { liberator.search.clear(); }, + function () { search.clear(); }, { argCount: "0" }); /////////////////////////////////////////////////////////////////////////////}}} @@ -317,14 +317,14 @@ liberator.Search = function () //{{{ // If you omit "mode", it will default to forward searching openSearchDialog: function (mode) { - if (mode == liberator.modes.SEARCH_BACKWARD) + if (mode == modes.SEARCH_BACKWARD) { - liberator.commandline.open("?", "", liberator.modes.SEARCH_BACKWARD); + commandline.open("?", "", modes.SEARCH_BACKWARD); backwards = true; } else { - liberator.commandline.open("/", "", liberator.modes.SEARCH_FORWARD); + commandline.open("/", "", modes.SEARCH_FORWARD); backwards = false; } @@ -343,7 +343,7 @@ liberator.Search = function () //{{{ found = fastFind.find(searchString, linksOnly) != Components.interfaces.nsITypeAheadFind.FIND_NOTFOUND; if (!found) - setTimeout(function () { liberator.echoerr("E486: Pattern not found: " + searchPattern); }, 0); + setTimeout(function () { echoerr("E486: Pattern not found: " + searchPattern); }, 0); return found; }, @@ -362,7 +362,7 @@ liberator.Search = function () //{{{ if (result == Components.interfaces.nsITypeAheadFind.FIND_NOTFOUND) { - liberator.echoerr("E486: Pattern not found: " + lastSearchPattern); + echoerr("E486: Pattern not found: " + lastSearchPattern); } else if (result == Components.interfaces.nsITypeAheadFind.FIND_WRAPPED) { @@ -370,18 +370,18 @@ liberator.Search = function () //{{{ // our command line setTimeout(function () { if (up) - liberator.commandline.echo("search hit TOP, continuing at BOTTOM", - liberator.commandline.HL_WARNINGMSG, liberator.commandline.APPEND_TO_MESSAGES); + commandline.echo("search hit TOP, continuing at BOTTOM", + commandline.HL_WARNINGMSG, commandline.APPEND_TO_MESSAGES); else - liberator.commandline.echo("search hit BOTTOM, continuing at TOP", - liberator.commandline.HL_WARNINGMSG, liberator.commandline.APPEND_TO_MESSAGES); + commandline.echo("search hit BOTTOM, continuing at TOP", + commandline.HL_WARNINGMSG, commandline.APPEND_TO_MESSAGES); }, 0); } else { - liberator.echo((up ? "?" : "/") + lastSearchPattern, null, liberator.commandline.FORCE_SINGLELINE); + echo((up ? "?" : "/") + lastSearchPattern, null, commandline.FORCE_SINGLELINE); - if (liberator.options["hlsearch"]) + if (options["hlsearch"]) this.highlight(lastSearchString); } }, @@ -389,7 +389,7 @@ liberator.Search = function () //{{{ // Called when the user types a key in the search dialog. Triggers a find attempt if 'incsearch' is set searchKeyPressed: function (command) { - if (liberator.options["incsearch"]) + if (options["incsearch"]) this.find(command, backwards); }, @@ -405,7 +405,7 @@ liberator.Search = function () //{{{ command = lastSearchPattern; this.clear(); - if (!liberator.options["incsearch"] || !found) + if (!options["incsearch"] || !found) this.find(command, backwards); lastSearchBackwards = backwards; @@ -416,12 +416,12 @@ liberator.Search = function () //{{{ // TODO: move to find() when reverse incremental searching is kludged in // need to find again for reverse searching if (backwards) - setTimeout(function () { liberator.search.findAgain(false); }, 0); + setTimeout(function () { search.findAgain(false); }, 0); - if (liberator.options["hlsearch"]) + if (options["hlsearch"]) this.highlight(searchString); - liberator.modes.reset(); + modes.reset(); }, // Called when the search is canceled - for example if someone presses @@ -436,7 +436,7 @@ liberator.Search = function () //{{{ // this is not dependent on the value of 'hlsearch' highlight: function (text) { - if (liberator.config.name == "Muttator") + if (config.name == "Muttator") return; // already highlighted? diff --git a/content/hints.js b/content/hints.js index 3a46f280..de64a4de 100644 --- a/content/hints.js +++ b/content/hints.js @@ -26,13 +26,13 @@ the provisions above, a recipient may use your version of this file under the terms of any one of the MPL, the GPL or the LGPL. }}} ***** END LICENSE BLOCK *****/ -liberator.Hints = function () //{{{ +with (liberator) liberator.Hints = function () //{{{ { //////////////////////////////////////////////////////////////////////////////// ////////////////////// PRIVATE SECTION ///////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ - var modes = liberator.config.browserModes || [liberator.modes.NORMAL]; + var myModes = config.browserModes || [modes.NORMAL]; var submode = ""; // used for extended mode, can be "o", "t", "y", etc. var hintString = ""; // the typed string part of the hint is in this string @@ -54,7 +54,7 @@ liberator.Hints = function () //{{{ // reset all important variables function reset() { - liberator.statusline.updateInputBuffer(""); + statusline.updateInputBuffer(""); hintString = ""; hintNumber = 0; usedTabKey = false; @@ -71,7 +71,7 @@ liberator.Hints = function () //{{{ function updateStatusline() { - liberator.statusline.updateInputBuffer((escapeNumbers ? liberator.mappings.getMapLeader() + " " : "") + // sign for escapeNumbers + statusline.updateInputBuffer((escapeNumbers ? mappings.getMapLeader() + " " : "") + // sign for escapeNumbers (hintString ? "\"" + hintString + "\"" : "") + (hintNumber > 0 ? " <" + hintNumber + ">" : "")); } @@ -87,11 +87,11 @@ liberator.Hints = function () //{{{ var scrollX = doc.defaultView.scrollX; var scrollY = doc.defaultView.scrollY; - var baseNodeAbsolute = liberator.util.xmlToDom( + var baseNodeAbsolute = util.xmlToDom( , doc); var elem, tagname, text, span, rect; - var res = liberator.buffer.evaluateXPath(liberator.options["hinttags"], doc, null, true); + var res = buffer.evaluateXPath(options["hinttags"], doc, null, true); var fragment = doc.createDocumentFragment(); var start = hints.length; @@ -147,19 +147,19 @@ liberator.Hints = function () //{{{ { var oldElem = validHints[oldID - 1]; if (oldElem) - oldElem.style.backgroundColor = liberator.options["linkbgcolor"]; + oldElem.style.backgroundColor = options["linkbgcolor"]; var newElem = validHints[newID - 1]; if (newElem) - newElem.style.backgroundColor = liberator.options["activelinkbgcolor"]; + newElem.style.backgroundColor = options["activelinkbgcolor"]; } function showHints() { - var linkfgcolor = liberator.options["linkfgcolor"]; - var linkbgcolor = liberator.options["linkbgcolor"]; - var activelinkfgcolor = liberator.options["activelinkfgcolor"]; - var activelinkbgcolor = liberator.options["activelinkbgcolor"]; + var linkfgcolor = options["linkfgcolor"]; + var linkbgcolor = options["linkbgcolor"]; + var activelinkfgcolor = options["activelinkfgcolor"]; + var activelinkbgcolor = options["activelinkbgcolor"]; var elem, tagname, text, rect, span, imgspan; var hintnum = 1; @@ -176,12 +176,10 @@ liberator.Hints = function () //{{{ var scrollY = doc.defaultView.scrollY; inner: - for (let i = start; i <= end; i++) + for (let i in (util.rangeInterruptable(start, end + 1, 500))) { - elem = hints[i][0]; - text = hints[i][1]; - span = hints[i][2]; - imgspan = hints[i][3]; + let hint = hints[i]; + [elem, text, span, imgspan] = hint; if (!validHint(text)) { @@ -190,8 +188,8 @@ liberator.Hints = function () //{{{ imgspan.style.display = "none"; // reset background color - elem.style.backgroundColor = hints[i][4]; - elem.style.color = hints[i][5]; + elem.style.backgroundColor = hint[4]; + elem.style.color = hint[5]; continue inner; } @@ -212,7 +210,7 @@ liberator.Hints = function () //{{{ imgspan.style.width = (rect.right - rect.left) + "px"; imgspan.style.height = (rect.bottom - rect.top) + "px"; imgspan.className = "liberator-hint"; - hints[i][3] = imgspan; + hint[3] = imgspan; doc.body.appendChild(imgspan); } imgspan.style.backgroundColor = (activeHint == hintnum) ? activelinkbgcolor : linkbgcolor; @@ -245,22 +243,23 @@ liberator.Hints = function () //{{{ for (let i = start; i <= end; i++) { + let hint = hits[i]; // remove the span for the numeric display part - doc.body.removeChild(hints[i][2]); - if (hints[i][3]) // a transparent span for images - doc.body.removeChild(hints[i][3]); + doc.body.removeChild(hint[2]); + if (hint[3]) // a transparent span for images + doc.body.removeChild(hint[3]); - if (timeout && firstElem == hints[i][0]) + if (timeout && firstElem == hint[0]) { - firstElemBgColor = hints[i][4]; - firstElemColor = hints[i][5]; + firstElemBgColor = hint[4]; + firstElemColor = hint[5]; } else { // restore colors - var elem = hints[i][0]; - elem.style.backgroundColor = hints[i][4]; - elem.style.color = hints[i][5]; + var elem = hint[0]; + elem.style.backgroundColor = hint[4]; + elem.style.color = hint[5]; } } @@ -304,7 +303,7 @@ liberator.Hints = function () //{{{ { if (validHints.length == 0) { - liberator.beep(); + beep(); return false; } @@ -326,50 +325,50 @@ liberator.Hints = function () //{{{ var loc = elem.href || ""; switch (submode) { - case ";": liberator.buffer.focusElement(elem); break; - case "?": liberator.buffer.showElementInfo(elem); break; - case "a": liberator.buffer.saveLink(elem, false); break; - case "s": liberator.buffer.saveLink(elem, true); break; - case "o": liberator.buffer.followLink(elem, liberator.CURRENT_TAB); break; - case "O": liberator.commandline.open(":", "open " + loc, liberator.modes.EX); break; - case "t": liberator.buffer.followLink(elem, liberator.NEW_TAB); break; - case "b": liberator.buffer.followLink(elem, liberator.NEW_BACKGROUND_TAB); break; - case "T": liberator.commandline.open(":", "tabopen " + loc, liberator.modes.EX); break; - case "v": liberator.buffer.viewSource(loc, false); break; - case "V": liberator.buffer.viewSource(loc, true); break; - case "w": liberator.buffer.followLink(elem, liberator.NEW_WINDOW); break; - case "W": liberator.commandline.open(":", "winopen " + loc, liberator.modes.EX); break; - case "y": setTimeout(function () { liberator.util.copyToClipboard(loc, true); }, timeout + 50); break; - case "Y": setTimeout(function () { liberator.util.copyToClipboard(elem.textContent || "", true); }, timeout + 50); break; + case ";": buffer.focusElement(elem); break; + case "?": buffer.showElementInfo(elem); break; + case "a": buffer.saveLink(elem, false); break; + case "s": buffer.saveLink(elem, true); break; + case "o": buffer.followLink(elem, CURRENT_TAB); break; + case "O": commandline.open(":", "open " + loc, modes.EX); break; + case "t": buffer.followLink(elem, NEW_TAB); break; + case "b": buffer.followLink(elem, NEW_BACKGROUND_TAB); break; + case "T": commandline.open(":", "tabopen " + loc, modes.EX); break; + case "v": buffer.viewSource(loc, false); break; + case "V": buffer.viewSource(loc, true); break; + case "w": buffer.followLink(elem, NEW_WINDOW); break; + case "W": commandline.open(":", "winopen " + loc, modes.EX); break; + case "y": setTimeout(function () { util.copyToClipboard(loc, true); }, timeout + 50); break; + case "Y": setTimeout(function () { util.copyToClipboard(elem.textContent || "", true); }, timeout + 50); break; default: - liberator.echoerr("INTERNAL ERROR: unknown submode: " + submode); + echoerr("INTERNAL ERROR: unknown submode: " + submode); } removeHints(timeout); - if (liberator.modes.extended & liberator.modes.ALWAYS_HINT) + if (modes.extended & modes.ALWAYS_HINT) { setTimeout(function () { canUpdate = true; hintString = ""; hintNumber = 0; - liberator.statusline.updateInputBuffer(""); + statusline.updateInputBuffer(""); }, timeout); } else { - if (timeout == 0 || liberator.modes.isReplaying) + if (timeout == 0 || modes.isReplaying) { // force a possible mode change, based on wheter an input field has focus - liberator.events.onFocusChange(); - if (liberator.mode == liberator.modes.HINTS) - liberator.modes.reset(false); + events.onFocusChange(); + if (mode == modes.HINTS) + modes.reset(false); } else { - liberator.modes.add(liberator.modes.INACTIVE_HINT); + modes.add(modes.INACTIVE_HINT); setTimeout(function () { - if (liberator.mode == liberator.modes.HINTS) - liberator.modes.pop(); + if (mode == modes.HINTS) + modes.pop(); }, timeout); } } @@ -400,7 +399,7 @@ liberator.Hints = function () //{{{ function wordStartsWithMatcher(hintString, allowWordOverleaping) //{{{ { var hintStrings = hintString.split(/ +/); - var wordSplitRegex = new RegExp(liberator.options["wordseparators"]); + var wordSplitRegex = new RegExp(options["wordseparators"]); function charsAtBeginningOfWords(chars, words, allowWordOverleaping) { @@ -530,14 +529,14 @@ liberator.Hints = function () //{{{ return wordStartsWith; } //}}} - var hintMatching = liberator.options["hintmatching"]; + var hintMatching = options["hintmatching"]; switch (hintMatching) { case "contains" : return containsMatcher(hintString); case "wordstartswith": return wordStartsWithMatcher(hintString, /*allowWordOverleaping=*/ true); case "firstletters" : return wordStartsWithMatcher(hintString, /*allowWordOverleaping=*/ false); - case "custom" : return liberator.plugins.customHintMatcher(hintString); - default : liberator.echoerr("Invalid hintmatching type: " + hintMatching); + case "custom" : return plugins.customHintMatcher(hintString); + default : echoerr("Invalid hintmatching type: " + hintMatching); } return null; } //}}} @@ -551,36 +550,36 @@ liberator.Hints = function () //{{{ "//xhtml:*[@onclick or @onmouseover or @onmousedown or @onmouseup or @oncommand or @class='lk' or @class='s'] | " + "//xhtml:input[not(@type='hidden')] | //xhtml:a | //xhtml:area | //xhtml:iframe | //xhtml:textarea | //xhtml:button | //xhtml:select"; - liberator.options.add(["extendedhinttags", "eht"], + options.add(["extendedhinttags", "eht"], "XPath string of hintable elements activated by ';'", "string", DEFAULT_HINTTAGS); - liberator.options.add(["hinttags", "ht"], + options.add(["hinttags", "ht"], "XPath string of hintable elements activated by 'f' and 'F'", "string", DEFAULT_HINTTAGS); - liberator.options.add(["hinttimeout", "hto"], + options.add(["hinttimeout", "hto"], "Automatically follow non unique numerical hint", "number", 0, { validator: function (value) value >= 0 }); - liberator.options.add(["linkfgcolor", "lfc"], + options.add(["linkfgcolor", "lfc"], "Foreground color of a link during hint mode", "string", "black"); - liberator.options.add(["linkbgcolor", "lbc"], + options.add(["linkbgcolor", "lbc"], "Background color of a link during hint mode", "string", "yellow"); - liberator.options.add(["activelinkfgcolor", "alfc"], + options.add(["activelinkfgcolor", "alfc"], "Foreground color of the current active link during hint mode", "string", "black"); - liberator.options.add(["activelinkbgcolor", "albc"], + options.add(["activelinkbgcolor", "albc"], "Background color of the current active link during hint mode", "string", "#88FF00"); - liberator.options.add(["hintmatching", "hm"], + options.add(["hintmatching", "hm"], "How links are matched", "string", "contains", { @@ -591,7 +590,7 @@ liberator.Hints = function () //{{{ validator: function (value) /^(contains|wordstartswith|firstletters|custom)$/.test(value) }); - liberator.options.add(["wordseparators", "wsp"], + options.add(["wordseparators", "wsp"], "How words are split for hintmatching", "string", '[\\.,!\\?:;/\\\"\\^\\$%&?\\(\\)\\[\\]\\{\\}<>#\\*\\+\\|=~ _\\-]'); @@ -599,26 +598,26 @@ liberator.Hints = function () //{{{ ////////////////////// MAPPINGS //////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ - liberator.mappings.add(modes, ["f"], + mappings.add(myModes, ["f"], "Start QuickHint mode", - function () { liberator.hints.show(liberator.modes.QUICK_HINT); }); + function () { hints.show(modes.QUICK_HINT); }); - liberator.mappings.add(modes, ["F"], + mappings.add(myModes, ["F"], "Start QuickHint mode, but open link in a new tab", - function () { liberator.hints.show(liberator.modes.QUICK_HINT, "t"); }); + function () { hints.show(modes.QUICK_HINT, "t"); }); - liberator.mappings.add(modes, [";"], + mappings.add(myModes, [";"], "Start an extended hint mode", function (arg) { if (arg == "f") - liberator.hints.show(liberator.modes.ALWAYS_HINT, "o"); + hints.show(modes.ALWAYS_HINT, "o"); else if (arg == "F") - liberator.hints.show(liberator.modes.ALWAYS_HINT, "t"); + hints.show(modes.ALWAYS_HINT, "t"); else - liberator.hints.show(liberator.modes.EXTENDED_HINT, arg); + hints.show(modes.EXTENDED_HINT, arg); }, - { flags: liberator.Mappings.flags.ARGUMENT }); + { flags: Mappings.flags.ARGUMENT }); /////////////////////////////////////////////////////////////////////////////}}} ////////////////////// PUBLIC SECTION ////////////////////////////////////////// @@ -628,13 +627,13 @@ liberator.Hints = function () //{{{ show: function (mode, minor, filter, win) { - if (mode == liberator.modes.EXTENDED_HINT && !/^[;?asoOtbTvVwWyY]$/.test(minor)) + if (mode == modes.EXTENDED_HINT && !/^[;?asoOtbTvVwWyY]$/.test(minor)) { - liberator.beep(); + beep(); return; } - liberator.modes.push(liberator.modes.HINTS, mode, win != undefined); + modes.push(modes.HINTS, mode, win != undefined); submode = minor || "o"; // open is the default mode hintString = filter || ""; hintNumber = 0; @@ -643,15 +642,15 @@ liberator.Hints = function () //{{{ generate(win); // get all keys from the input queue - liberator.threadYield(true); + threadYield(true); canUpdate = true; showHints(); if (validHints.length == 0) { - liberator.beep(); - liberator.modes.reset(); + beep(); + modes.reset(); return false; } else if (validHints.length == 1) @@ -670,7 +669,7 @@ liberator.Hints = function () //{{{ onEvent: function (event) { - var key = liberator.events.toString(event); + var key = events.toString(event); var followFirst = false; // clear any timeout which might be active after pressing a number @@ -726,7 +725,7 @@ liberator.Hints = function () //{{{ { usedTabKey = false; hintNumber = 0; - liberator.beep(); + beep(); return; } break; @@ -737,7 +736,7 @@ liberator.Hints = function () //{{{ hintNumber = 0; break; - case liberator.mappings.getMapLeader(): + case mappings.getMapLeader(): escapeNumbers = !escapeNumbers; if (escapeNumbers && usedTabKey) // hintNumber not used normally, but someone may wants to toggle hintNumber = 0; // s ? reset. Prevent to show numbers not entered. @@ -750,14 +749,14 @@ liberator.Hints = function () //{{{ if (/^<./.test(key) || key == ":") { var map = null; - if ((map = liberator.mappings.get(liberator.modes.NORMAL, key)) || - (map = liberator.mappings.get(liberator.modes.HINTS, key))) + if ((map = mappings.get(modes.NORMAL, key)) || + (map = mappings.get(modes.HINTS, key))) { map.execute(null, -1); return; } - liberator.beep(); + beep(); return; } @@ -786,7 +785,7 @@ liberator.Hints = function () //{{{ if (hintNumber == 0 || hintNumber > validHints.length) { - liberator.beep(); + beep(); return; } @@ -794,7 +793,7 @@ liberator.Hints = function () //{{{ // the hint after a timeout, as the user might have wanted to follow link 34 if (hintNumber > 0 && hintNumber * 10 <= validHints.length) { - var timeout = liberator.options["hinttimeout"]; + var timeout = options["hinttimeout"]; if (timeout > 0) activeTimeout = setTimeout(function () { processHints(true); }, timeout); diff --git a/content/io.js b/content/io.js index c227b9d4..9554d4f9 100644 --- a/content/io.js +++ b/content/io.js @@ -28,14 +28,14 @@ the terms of any one of the MPL, the GPL or the LGPL. }}} ***** END LICENSE BLOCK *****/ // TODO: why are we passing around strings rather than file objects? -liberator.IO = function () //{{{ +with (liberator) liberator.IO = function () //{{{ { //////////////////////////////////////////////////////////////////////////////// ////////////////////// PRIVATE SECTION ///////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ const WINDOWS = navigator.platform == "Win32"; - const EXTENSION_NAME = liberator.config.name.toLowerCase(); // "vimperator" or "muttator" + const EXTENSION_NAME = config.name.toLowerCase(); // "vimperator" or "muttator" var environmentService = Components.classes["@mozilla.org/process/environment;1"] .getService(Components.interfaces.nsIEnvironment); @@ -69,7 +69,7 @@ liberator.IO = function () //{{{ function expandPathList(list) { - return list.split(",").map(liberator.io.expandPath).join(","); + return list.split(",").map(io.expandPath).join(","); } // TODO: why are we passing around so many strings? I know that the XPCOM @@ -89,22 +89,22 @@ liberator.IO = function () //{{{ ////////////////////// OPTIONS //////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ - liberator.options.add(["cdpath", "cd"], + options.add(["cdpath", "cd"], "List of directories searched when executing :cd", "stringlist", cdpath, { setter: function (value) expandPathList(value) }); - liberator.options.add(["runtimepath", "rtp"], + options.add(["runtimepath", "rtp"], "List of directories searched for runtime files", "stringlist", runtimepath, { setter: function (value) expandPathList(value) }); - liberator.options.add(["shell", "sh"], + options.add(["shell", "sh"], "Shell to use for executing :! and :run commands", "string", shell, - { setter: function (value) liberator.io.expandPath(value) }); + { setter: function (value) io.expandPath(value) }); - liberator.options.add(["shellcmdflag", "shcf"], + options.add(["shellcmdflag", "shcf"], "Flag passed to shell when executing :! and :run commands", "string", shellcmdflag); @@ -112,7 +112,7 @@ liberator.IO = function () //{{{ ////////////////////// COMMANDS //////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ - liberator.commands.add(["cd", "chd[ir]"], + commands.add(["cd", "chd[ir]"], "Change the current directory", function (args) { @@ -128,28 +128,28 @@ liberator.IO = function () //{{{ } else { - liberator.echoerr("E186: No previous directory"); + echoerr("E186: No previous directory"); return; } } - args = liberator.io.expandPath(args); + args = io.expandPath(args); // go directly to an absolute path or look for a relative path // match in 'cdpath' if (/^(~|\/|[a-z]:|\.\/|\.\.\/)/i.test(args)) { // TODO: apparently we don't handle ../ or ./ paths yet - if (liberator.io.setCurrentDirectory(args)) - liberator.echo(liberator.io.getCurrentDirectory()); + if (io.setCurrentDirectory(args)) + echo(io.getCurrentDirectory()); } else { - var directories = liberator.options["cdpath"].replace(/^,$|^,,|,,$/, "").split(","); + var directories = options["cdpath"].replace(/^,$|^,,|,,$/, "").split(","); // empty 'cdpath' items mean the current directory directories = directories.map( - function (directory) directory == "" ? liberator.io.getCurrentDirectory() : directory + function (directory) directory == "" ? io.getCurrentDirectory() : directory ); var directoryFound = false; @@ -157,11 +157,11 @@ liberator.IO = function () //{{{ for (let i = 0; i < directories.length; i++) { var dir = joinPaths(directories[i], args); - if (liberator.io.setCurrentDirectory(dir)) + if (io.setCurrentDirectory(dir)) { // FIXME: we're just overwriting the error message from // setCurrentDirectory here - liberator.echo(liberator.io.getCurrentDirectory()); + echo(io.getCurrentDirectory()); directoryFound = true; break; } @@ -169,27 +169,27 @@ liberator.IO = function () //{{{ if (!directoryFound) { - liberator.echoerr("E344: Can't find directory \"" + args + "\" in cdpath" + echoerr("E344: Can't find directory \"" + args + "\" in cdpath" + "\n" + "E472: Command failed"); } } }, - { completer: function (filter) liberator.completion.file(filter, true) }); + { completer: function (filter) completion.file(filter, true) }); // NOTE: this command is only used in :source - liberator.commands.add(["fini[sh]"], + commands.add(["fini[sh]"], "Stop sourcing a script file", - function () { liberator.echoerr("E168: :finish used outside of a sourced file"); }, + function () { echoerr("E168: :finish used outside of a sourced file"); }, { argCount: "0" }); - liberator.commands.add(["pw[d]"], + commands.add(["pw[d]"], "Print the current directory name", - function () { liberator.echo(liberator.io.getCurrentDirectory()); }, + function () { echo(io.getCurrentDirectory()); }, { argCount: "0" }); // "mkv[imperatorrc]" or "mkm[uttatorrc]" - liberator.commands.add([EXTENSION_NAME.replace(/(.)(.*)/, "mk$1[$2rc]")], + commands.add([EXTENSION_NAME.replace(/(.)(.*)/, "mk$1[$2rc]")], "Write current key mappings and changed options to the config file", function (args, special) { @@ -200,27 +200,26 @@ liberator.IO = function () //{{{ else filename = "~/" + (WINDOWS ? "_" : ".") + EXTENSION_NAME + "rc"; - var file = liberator.io.getFile(filename); + var file = io.getFile(filename); if (file.exists() && !special) { - liberator.echoerr("E189: \"" + filename + "\" exists (add ! to override)"); + echoerr("E189: \"" + filename + "\" exists (add ! to override)"); return; } - var line = "\" " + liberator.version + "\n"; + var line = "\" " + version + "\n"; line += "\" Mappings\n"; - var modes = [[[liberator.modes.NORMAL], ""], [[liberator.modes.COMMAND_LINE], "c"], - [[liberator.modes.INSERT, liberator.modes.TEXTAREA], "i"]]; - for (let i = 0; i < modes.length; i++) - { + [[[modes.NORMAL], ""], + [[modes.COMMAND_LINE], "c"], + [[modes.INSERT, modes.TEXTAREA], "i"]].forEach(function ([modes, modechar]) { // NOTE: names.length is always 1 on user maps. If that changes, also fix getUserIterator and v.m.list - for (let map in liberator.mappings.getUserIterator(modes[i][0])) - line += modes[i][1] + (map.noremap ? "nore" : "") + "map " + map.names[0] + " " + map.rhs + "\n"; - } + for (let map in mappings.getUserIterator(modes)) + line += modechar + (map.noremap ? "noremap" : "map") + " " + map.names[0] + " " + map.rhs + "\n"; + }); line += "\n\" Options\n"; - for (let option in liberator.options) + for (let option in options) { // TODO: options should be queried for this info // TODO: string/list options might need escaping in future @@ -235,15 +234,15 @@ liberator.IO = function () //{{{ // :mkvimrc doesn't save autocommands, so we don't either - remove this code at some point // line += "\n\" Auto-Commands\n"; - // for (let item in liberator.autocommands) + // for (let item in autocommands) // line += "autocmd " + item.event + " " + item.pattern.source + " " + item.command + "\n"; line += "\n\" Abbreviations\n"; - for (let abbrCmd in liberator.editor.abbreviations) + for (let abbrCmd in editor.abbreviations) line += abbrCmd; - // if (liberator.mappings.getMapLeader() != "\\") - // line += "\nlet mapleader = \"" + liberator.mappings.getMapLeader() + "\"\n"; + // if (mappings.getMapLeader() != "\\") + // line += "\nlet mapleader = \"" + mappings.getMapLeader() + "\"\n"; // source a user .vimperatorrc file line += "\nsource! " + filename + ".local\n"; @@ -251,20 +250,20 @@ liberator.IO = function () //{{{ try { - liberator.io.writeFile(file, line); + io.writeFile(file, line); } catch (e) { - liberator.echoerr("E190: Cannot open \"" + filename + "\" for writing"); - liberator.log("Could not write to " + file.path + ": " + e.message); // XXX + echoerr("E190: Cannot open \"" + filename + "\" for writing"); + log("Could not write to " + file.path + ": " + e.message); // XXX } }, { bang: true, - completer: function (filter) liberator.completion.file(filter, true) + completer: function (filter) completion.file(filter, true) }); - liberator.commands.add(["ru[ntime]"], + commands.add(["ru[ntime]"], "Source the specified file from each directory in 'runtimepath'", function (args, special) { @@ -272,25 +271,25 @@ liberator.IO = function () //{{{ // : wildcards/regexp // : unify with startup sourcing loop let paths = args.arguments; - let runtimeDirs = liberator.options["runtimepath"].split(","); + let runtimeDirs = options["runtimepath"].split(","); let found = false; // FIXME: should use original arg string - liberator.echomsg("Searching for \"" + paths.join(" ") + "\" in \"" + liberator.options["runtimepath"] + "\"", 2); + echomsg("Searching for \"" + paths.join(" ") + "\" in \"" + options["runtimepath"] + "\"", 2); outer: for (let [,runtimeDir] in Iterator(runtimeDirs)) { for (let [,path] in Iterator(paths)) { - let file = liberator.io.getFile(joinPaths(runtimeDir, path)); + let file = io.getFile(joinPaths(runtimeDir, path)); - liberator.echomsg("Searching for \"" + file.path + "\" in \"", 3); + echomsg("Searching for \"" + file.path + "\" in \"", 3); if (file.exists() && file.isReadable() && !file.isDirectory()) // XXX { found = true; - liberator.io.source(file.path, false); + io.source(file.path, false); if (!special) break outer; @@ -299,7 +298,7 @@ liberator.IO = function () //{{{ } if (!found) - liberator.echomsg("not found in 'runtimepath': \"" + paths.join(" ") + "\"", 1); // FIXME: should use original arg string + echomsg("not found in 'runtimepath': \"" + paths.join(" ") + "\"", 1); // FIXME: should use original arg string }, { argCount: "+", @@ -307,36 +306,36 @@ liberator.IO = function () //{{{ } ); - liberator.commands.add(["scrip[tnames]"], + commands.add(["scrip[tnames]"], "List all sourced script names", function () { - var list = liberator.template.tabular(["", "Filename"], ["text-align: right; padding-right: 1em;"], + var list = template.tabular(["", "Filename"], ["text-align: right; padding-right: 1em;"], ([i + 1, file] for ([i, file] in Iterator(scriptNames)))); // TODO: add colon? - liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); + commandline.echo(list, commandline.HL_NORMAL, commandline.FORCE_MULTILINE); }, { argCount: "0" }); - liberator.commands.add(["so[urce]"], + commands.add(["so[urce]"], "Read Ex commands from a file", function (args, special) { // FIXME: implement proper filename quoting - "E172: Only one file name allowed" if (!args) { - liberator.echoerr("E471: Argument required"); + echoerr("E471: Argument required"); return; } - liberator.io.source(args, special); + io.source(args, special); }, { bang: true, - completer: function (filter) liberator.completion.file(filter, true) + completer: function (filter) completion.file(filter, true) }); - liberator.commands.add(["!", "run"], + commands.add(["!", "run"], "Run a command", function (args, special) { @@ -349,12 +348,12 @@ liberator.IO = function () //{{{ args = args.replace(/(^|[^\\])!/g, "$1" + lastRunCommand); lastRunCommand = args; - var output = liberator.io.system(args); - var command = ":" + liberator.util.escapeHTML(liberator.commandline.getCommand()) + "
"; + var output = io.system(args); + var command = ":" + util.escapeHTML(commandline.getCommand()) + "
"; - liberator.echo(command + liberator.util.escapeHTML(output)); + echo(command + util.escapeHTML(output)); - liberator.autocommands.trigger("ShellCmdPost", {}); + autocommands.trigger("ShellCmdPost", {}); }, { bang: true }); @@ -440,7 +439,7 @@ liberator.IO = function () //{{{ if (!dir.exists() || !dir.isDirectory()) { - liberator.echoerr("E344: Can't find directory \"" + dir.path + "\" in path"); + echoerr("E344: Can't find directory \"" + dir.path + "\" in path"); return null; } @@ -452,9 +451,9 @@ liberator.IO = function () //{{{ getRuntimeDirectories: function (specialDirectory) { - let dirs = liberator.options["runtimepath"].split(","); + let dirs = options["runtimepath"].split(","); - dirs = dirs.map(function (dir) liberator.io.getFile(joinPaths(dir, specialDirectory))) + dirs = dirs.map(function (dir) io.getFile(joinPaths(dir, specialDirectory))) .filter(function (dir) dir.exists() && dir.isDirectory() && dir.isReadable()); return dirs; @@ -671,7 +670,7 @@ lookup: if (!file.exists()) { - liberator.echoerr("Command not found: " + program); + echoerr("Command not found: " + program); return -1; } @@ -688,7 +687,7 @@ lookup: // is fixed, should use that instead of a tmpfile system: function (command, input) { - liberator.echomsg("Calling shell to execute: " + command, 4); + echomsg("Calling shell to execute: " + command, 4); var stdoutFile = ioManager.createTempFile(); var stderrFile = ioManager.createTempFile(); @@ -714,7 +713,7 @@ lookup: command += " < \"" + escapeQuotes(stdinFile.path) + "\""; } - var res = ioManager.run(liberator.options["shell"], [liberator.options["shellcmdflag"], command], true); + var res = ioManager.run(options["shell"], [options["shellcmdflag"], command], true); if (res > 0) var output = ioManager.readFile(stderrFile) + "\nshell returned " + res; @@ -747,20 +746,20 @@ lookup: if (!silent) { if (file.exists() && file.isDirectory()) - liberator.echomsg("Cannot source a directory: \"" + filename + "\"", 0); + echomsg("Cannot source a directory: \"" + filename + "\"", 0); else - liberator.echomsg("could not source: \"" + filename + "\"", 1); + echomsg("could not source: \"" + filename + "\"", 1); - liberator.echoerr("E484: Can't open file " + filename); + echoerr("E484: Can't open file " + filename); } return; } - liberator.echomsg("sourcing \"" + filename + "\"", 2); + echomsg("sourcing \"" + filename + "\"", 2); let str = ioManager.readFile(file); - let uri = liberator.util.createURI(file.path); + let uri = util.createURI(file.path); // handle pure javascript files specially if (/\.js$/.test(filename)) @@ -779,7 +778,7 @@ lookup: } else if (/\.css$/.test(filename)) { - liberator.storage.styles.registerSheet(uri.spec, !silent, true); + storage.styles.registerSheet(uri.spec, !silent, true); } else { @@ -808,8 +807,8 @@ lookup: if (/^\s*(".*)?$/.test(line)) continue; - var [count, cmd, special, args] = liberator.commands.parseCommand(line); - var command = liberator.commands.get(cmd); + var [count, cmd, special, args] = commands.parseCommand(line); + var command = commands.get(cmd); if (!command) { @@ -818,11 +817,11 @@ lookup: // FIXME: messages need to be able to specify // whether they can be cleared/overwritten or // should be appended to and the MOW opened - liberator.echoerr("Error detected while processing " + file.path, - liberator.commandline.FORCE_MULTILINE); - liberator.commandline.echo("line " + lineNumber + ":", liberator.commandline.HL_LINENR, - liberator.commandline.APPEND_TO_MESSAGES); - liberator.echoerr("E492: Not an editor command: " + line); + echoerr("Error detected while processing " + file.path, + commandline.FORCE_MULTILINE); + commandline.echo("line " + lineNumber + ":", commandline.HL_LINENR, + commandline.APPEND_TO_MESSAGES); + echoerr("E492: Not an editor command: " + line); } else { @@ -850,7 +849,7 @@ lookup: else { // execute a normal liberator command - liberator.execute(line); + execute(line); } } } @@ -858,15 +857,15 @@ lookup: // if no heredoc-end delimiter is found before EOF then // process the heredoc anyway - Vim compatible ;-) - liberator.eval(heredoc); + eval(heredoc); } if (scriptNames.indexOf(file.path) == -1) scriptNames.push(file.path); - liberator.echomsg("finished sourcing \"" + filename + "\"", 2); + echomsg("finished sourcing \"" + filename + "\"", 2); - liberator.log("Sourced: " + file.path, 3); + log("Sourced: " + file.path, 3); } catch (e) { @@ -874,7 +873,7 @@ lookup: if (Components.utils.reportError) Components.utils.reportError(e); if (!silent) - liberator.echoerr(message); + echoerr(message); } } }; //}}} diff --git a/content/liberator.js b/content/liberator.js index c1029e48..7e3c594d 100644 --- a/content/liberator.js +++ b/content/liberator.js @@ -398,8 +398,8 @@ const liberator = (function () //{{{ { if (count > 1) { + let each, eachUnits, totalUnits; let total = 0; - var beforeTime = Date.now(); for (let i in liberator.util.rangeInterruptable(0, count, 500)) { @@ -413,23 +413,23 @@ const liberator = (function () //{{{ if (total / count >= 100) { - var each = (total / 1000.0) / count; - var eachUnits = "sec"; + each = total / 1000.0 / count; + eachUnits = "sec"; } else { - var each = total / count; - var eachUnits = "msec"; + each = total / count; + eachUnits = "msec"; } if (total >= 100) { - var total = total / 1000.0; - var totalUnits = "sec"; + total = total / 1000.0; + totalUnits = "sec"; } else { - var totalUnits = "msec"; + totalUnits = "msec"; } var str = liberator.template.generic( diff --git a/content/mail.js b/content/mail.js index 6526fb5f..4a60e10b 100644 --- a/content/mail.js +++ b/content/mail.js @@ -26,7 +26,7 @@ the provisions above, a recipient may use your version of this file under the terms of any one of the MPL, the GPL or the LGPL. }}} ***** END LICENSE BLOCK *****/ -liberator.Mail = function () //{{{ +with (liberator) liberator.Mail = function () //{{{ { //////////////////////////////////////////////////////////////////////////////// ////////////////////// PRIVATE SECTION ///////////////////////////////////////// @@ -54,7 +54,7 @@ liberator.Mail = function () //{{{ if (folder) { var msgFolder = folder.QueryInterface(Components.interfaces.nsIMsgFolder); - liberator.autocommands.trigger("FolderLoaded", {url: msgFolder}); + autocommands.trigger("FolderLoaded", {url: msgFolder}); // Jump to a message when requested var indices = []; @@ -92,7 +92,7 @@ liberator.Mail = function () //{{{ function getFolderCompletions(filter) { var completions = []; - var folders = liberator.mail.getFolders(); + var folders = mail.getFolders(); for (let folder = 0; folder < folders.length; folder++) { @@ -101,7 +101,7 @@ liberator.Mail = function () //{{{ "Unread: " + folders[folder].getNumUnread(false)]); } - return [0, liberator.completion.filter(completions, filter)]; + return [0, completion.filter(completions, filter)]; } function getRSSUrl() @@ -113,38 +113,38 @@ liberator.Mail = function () //{{{ { if (!destinationFolder) { - liberator.echoerr("E471: Argument required"); + echoerr("E471: Argument required"); return false; } - var folders = liberator.mail.getFolders(destinationFolder); + var folders = mail.getFolders(destinationFolder); if (folders.length == 0) { - liberator.echoerr("E94: No matching folder for " + destinationFolder); + echoerr("E94: No matching folder for " + destinationFolder); return false; } else if (folders.length > 1) { - liberator.echoerr("E93: More than one match for " + destinationFolder); + echoerr("E93: More than one match for " + destinationFolder); return false; } var count = gDBView.selection.count; if (!count) { - liberator.beep(); + beep(); return false; } if (copy) { MsgCopyMessage(folders[0]); - setTimeout(function () { liberator.echo(count + " message(s) copied to " + folders[0].prettyName); }, 100); + setTimeout(function () { echo(count + " message(s) copied to " + folders[0].prettyName); }, 100); } else { MsgMoveMessage(folders[0]); - setTimeout(function () { liberator.echo(count + " message(s) moved to " + folders[0].prettyName); }, 100); + setTimeout(function () { echo(count + " message(s) moved to " + folders[0].prettyName); }, 100); } return true; } @@ -184,7 +184,7 @@ liberator.Mail = function () //{{{ i += direction; } if (!folder || count > 0) - liberator.beep(); + beep(); else tree.view.selection.timedSelect(c + folder, tree._selectDelay); } @@ -199,11 +199,11 @@ liberator.Mail = function () //{{{ ////////////////////// OPTIONS ///////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ -// liberator.options.add(["editor"], +// options.add(["editor"], // "Set the external text editor", // "string", "gvim -f"); - liberator.options.add(["layout"], + options.add(["layout"], "Set the layout of the mail window", "string", "inherit", { @@ -222,7 +222,7 @@ liberator.Mail = function () //{{{ validator: function (value) /^(classic|wide|vertical|inherit)$/.test(value) }); - /*liberator.options.add(["threads"], + /*options.add(["threads"], "Use threading to group messages", "boolean", true, { @@ -241,232 +241,232 @@ liberator.Mail = function () //{{{ ////////////////////// MAPPINGS //////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ - var modes = liberator.config.mailModes || [liberator.modes.NORMAL]; + var myModes = config.mailModes || [modes.NORMAL]; - liberator.mappings.add(modes, ["", "i"], + mappings.add(myModes, ["", "i"], "Inspect (focus) message", function () { content.focus(); }); - liberator.mappings.add(modes, ["I"], + mappings.add(myModes, ["I"], "Open the message in new tab", function () { if (gDBView && gDBView.selection.count < 1) - return liberator.beep(); + return beep(); MsgOpenNewTabForMessage(); }); - /*liberator.mappings.add([liberator.modes.NORMAL], + /*mappings.add([modes.NORMAL], ["o"], "Open a message", - function () { liberator.commandline.open(":", "open ", liberator.modes.EX); });*/ + function () { commandline.open(":", "open ", modes.EX); });*/ - liberator.mappings.add(modes, [""], + mappings.add(myModes, [""], "Scroll message or select next unread one", function () true, - { flags: liberator.Mappings.flags.ALLOW_EVENT_ROUTING }); + { flags: Mappings.flags.ALLOW_EVENT_ROUTING }); - liberator.mappings.add(modes, ["t"], + mappings.add(myModes, ["t"], "Select thread", function () { gDBView.ExpandAndSelectThreadByIndex(GetThreadTree().currentIndex, false); }); - liberator.mappings.add(modes, ["d", ""], + mappings.add(myModes, ["d", ""], "Move mail to Trash folder", function () { goDoCommand("cmd_delete"); }); - liberator.mappings.add(modes, ["j", ""], + mappings.add(myModes, ["j", ""], "Select next message", - function (count) { liberator.mail.selectMessage(function (msg) true, false, false, false, count); }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { mail.selectMessage(function (msg) true, false, false, false, count); }, + { flags: Mappings.flags.COUNT }); - liberator.mappings.add(modes, ["gj"], + mappings.add(myModes, ["gj"], "Select next message, including closed threads", - function (count) { liberator.mail.selectMessage(function (msg) true, false, true, false, count); }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { mail.selectMessage(function (msg) true, false, true, false, count); }, + { flags: Mappings.flags.COUNT }); - liberator.mappings.add(modes, ["J", ""], + mappings.add(myModes, ["J", ""], "Select next unread message", - function (count) { liberator.mail.selectMessage(function (msg) !msg.isRead, true, true, false, count); }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { mail.selectMessage(function (msg) !msg.isRead, true, true, false, count); }, + { flags: Mappings.flags.COUNT }); - liberator.mappings.add(modes, ["k", ""], + mappings.add(myModes, ["k", ""], "Select previous message", - function (count) { liberator.mail.selectMessage(function (msg) true, false, false, true, count); }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { mail.selectMessage(function (msg) true, false, false, true, count); }, + { flags: Mappings.flags.COUNT }); - liberator.mappings.add(modes, ["gk"], + mappings.add(myModes, ["gk"], "Select previous message", - function (count) { liberator.mail.selectMessage(function (msg) true, false, true, true, count); }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { mail.selectMessage(function (msg) true, false, true, true, count); }, + { flags: Mappings.flags.COUNT }); - liberator.mappings.add(modes, ["K"], + mappings.add(myModes, ["K"], "Select previous unread message", - function (count) { liberator.mail.selectMessage(function (msg) !msg.isRead, true, true, true, count); }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { mail.selectMessage(function (msg) !msg.isRead, true, true, true, count); }, + { flags: Mappings.flags.COUNT }); - liberator.mappings.add(modes, ["*"], + mappings.add(myModes, ["*"], "Select next message from the same sender", function (count) { try { var author = gDBView.hdrForFirstSelectedMessage.mime2DecodedAuthor.toLowerCase(); - liberator.mail.selectMessage(function (msg) msg.mime2DecodedAuthor.toLowerCase().indexOf(author) == 0, true, true, false, count); + mail.selectMessage(function (msg) msg.mime2DecodedAuthor.toLowerCase().indexOf(author) == 0, true, true, false, count); } - catch (e) { liberator.beep(); } + catch (e) { beep(); } }, - { flags: liberator.Mappings.flags.COUNT }); + { flags: Mappings.flags.COUNT }); - liberator.mappings.add(modes, ["#"], + mappings.add(myModes, ["#"], "Select previous message from the same sender", function (count) { try { var author = gDBView.hdrForFirstSelectedMessage.mime2DecodedAuthor.toLowerCase(); - liberator.mail.selectMessage(function (msg) msg.mime2DecodedAuthor.toLowerCase().indexOf(author) == 0, true, true, true, count); + mail.selectMessage(function (msg) msg.mime2DecodedAuthor.toLowerCase().indexOf(author) == 0, true, true, true, count); } - catch (e) { liberator.beep(); } + catch (e) { beep(); } }, - { flags: liberator.Mappings.flags.COUNT }); + { flags: Mappings.flags.COUNT }); // SENDING MESSAGES - liberator.mappings.add(modes, ["m"], + mappings.add(myModes, ["m"], "Compose a new message", - function () { liberator.commandline.open(":", "message -subject=", liberator.modes.EX); }); + function () { commandline.open(":", "message -subject=", modes.EX); }); - liberator.mappings.add(modes, ["M"], + mappings.add(myModes, ["M"], "Compose a new message to the sender of selected mail", function () { try { var to = escapeRecipient(gDBView.hdrForFirstSelectedMessage.mime2DecodedAuthor); - liberator.commandline.open(":", "message " + to + " -subject=", liberator.modes.EX); + commandline.open(":", "message " + to + " -subject=", modes.EX); } catch (e) { - liberator.beep(); + beep(); } }); - liberator.mappings.add(modes, ["r"], + mappings.add(myModes, ["r"], "Reply to sender", function () { goDoCommand("cmd_reply"); }); - liberator.mappings.add(modes, ["R"], + mappings.add(myModes, ["R"], "Reply to all", function () { goDoCommand("cmd_replyall"); }); - liberator.mappings.add(modes, ["f"], + mappings.add(myModes, ["f"], "Forward message", function () { goDoCommand("cmd_forward"); }); - liberator.mappings.add(modes, ["F"], + mappings.add(myModes, ["F"], "Forward message inline", function () { goDoCommand("cmd_forwardInline"); }); // SCROLLING - liberator.mappings.add(modes, [""], + mappings.add(myModes, [""], "Scroll message down", - function (count) { liberator.buffer.scrollLines(count > 1 ? count : 1); }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { buffer.scrollLines(count > 1 ? count : 1); }, + { flags: Mappings.flags.COUNT }); - liberator.mappings.add(modes, [""], + mappings.add(myModes, [""], "Scroll message up", - function (count) { liberator.buffer.scrollLines(-(count > 1 ? count : 1)); }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { buffer.scrollLines(-(count > 1 ? count : 1)); }, + { flags: Mappings.flags.COUNT }); - liberator.mappings.add([liberator.modes.MESSAGE], [""], + mappings.add([modes.MESSAGE], [""], "Select previous message", - function (count) { liberator.mail.selectMessage(function (msg) true, false, false, true, count); }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { mail.selectMessage(function (msg) true, false, false, true, count); }, + { flags: Mappings.flags.COUNT }); - liberator.mappings.add([liberator.modes.MESSAGE], [""], + mappings.add([modes.MESSAGE], [""], "Select next message", - function (count) { liberator.mail.selectMessage(function (msg) true, false, false, false, count); }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { mail.selectMessage(function (msg) true, false, false, false, count); }, + { flags: Mappings.flags.COUNT }); // UNDO/REDO - liberator.mappings.add(modes, ["u"], + mappings.add(myModes, ["u"], "Undo", function () { if (messenger.canUndo()) messenger.undo(msgWindow); else - liberator.beep(); + beep(); }); - liberator.mappings.add(modes, [""], + mappings.add(myModes, [""], "Redo", function () { if (messenger.canRedo()) messenger.redo(msgWindow); else - liberator.beep(); + beep(); }); // GETTING MAIL - liberator.mappings.add(modes, ["gm"], + mappings.add(myModes, ["gm"], "Get new messages", - function () { liberator.mail.getNewMessages(); }); + function () { mail.getNewMessages(); }); - liberator.mappings.add(modes, ["gM"], + mappings.add(myModes, ["gM"], "Get new messages for current account only", - function () { liberator.mail.getNewMessages(true); }); + function () { mail.getNewMessages(true); }); // MOVING MAIL - liberator.mappings.add(modes, ["c"], + mappings.add(myModes, ["c"], "Change folders", - function () { liberator.commandline.open(":", "goto ", liberator.modes.EX); }); + function () { commandline.open(":", "goto ", modes.EX); }); - liberator.mappings.add(modes, ["s"], + mappings.add(myModes, ["s"], "Move selected messages", - function () { liberator.commandline.open(":", "moveto ", liberator.modes.EX); }); + function () { commandline.open(":", "moveto ", modes.EX); }); - liberator.mappings.add(modes, ["S"], + mappings.add(myModes, ["S"], "Copy selected messages", - function () { liberator.commandline.open(":", "copyto ", liberator.modes.EX); }); + function () { commandline.open(":", "copyto ", modes.EX); }); - liberator.mappings.add(modes, [""], + mappings.add(myModes, [""], "Archive message", function () { moveOrCopy(false, "Archive"); }); - liberator.mappings.add(modes, ["]s"], + mappings.add(myModes, ["]s"], "Select next starred message", - function (count) { liberator.mail.selectMessage(function (msg) msg.isFlagged, true, true, false, count); }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { mail.selectMessage(function (msg) msg.isFlagged, true, true, false, count); }, + { flags: Mappings.flags.COUNT }); - liberator.mappings.add(modes, ["[s"], + mappings.add(myModes, ["[s"], "Select previous starred message", - function (count) { liberator.mail.selectMessage(function (msg) msg.isFlagged, true, true, true, count); }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { mail.selectMessage(function (msg) msg.isFlagged, true, true, true, count); }, + { flags: Mappings.flags.COUNT }); - liberator.mappings.add(modes, ["]a"], + mappings.add(myModes, ["]a"], "Select next message with an attachment", - function (count) { liberator.mail.selectMessage(function (msg) gDBView.db.HasAttachments(msg.messageKey), true, true, false, count); }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { mail.selectMessage(function (msg) gDBView.db.HasAttachments(msg.messageKey), true, true, false, count); }, + { flags: Mappings.flags.COUNT }); - liberator.mappings.add(modes, ["[a"], + mappings.add(myModes, ["[a"], "Select previous message with an attachment", - function (count) { liberator.mail.selectMessage(function (msg) gDBView.db.HasAttachments(msg.messageKey), true, true, true, count); }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { mail.selectMessage(function (msg) gDBView.db.HasAttachments(msg.messageKey), true, true, true, count); }, + { flags: Mappings.flags.COUNT }); // FOLDER SWITCHING - liberator.mappings.add(modes, ["gi"], + mappings.add(myModes, ["gi"], "Go to inbox", function (count) { - var folder = liberator.mail.getFolders("Inbox", false, true)[(count > 0) ? (count - 1) : 0]; + var folder = mail.getFolders("Inbox", false, true)[(count > 0) ? (count - 1) : 0]; if (folder) SelectFolder(folder.URI); else - liberator.beep(); + beep(); }, - { flags: liberator.Mappings.flags.COUNT }); + { flags: Mappings.flags.COUNT }); - liberator.mappings.add(modes, [""], + mappings.add(myModes, [""], "Select next folder", function (count) { @@ -475,22 +475,22 @@ liberator.Mail = function () //{{{ var c = tree.currentIndex; if (c + count >= tree.view.rowCount) { - liberator.beep(); + beep(); return; } tree.view.selection.timedSelect(c + count, tree._selectDelay ); }, - { flags: liberator.Mappings.flags.COUNT }); + { flags: Mappings.flags.COUNT }); - liberator.mappings.add(modes, [""], + mappings.add(myModes, [""], "Go to next mailbox with unread messages", function (count) { selectUnreadFolder(false, count); }, - { flags: liberator.Mappings.flags.COUNT }); + { flags: Mappings.flags.COUNT }); - liberator.mappings.add(modes, [""], + mappings.add(myModes, [""], "Select previous folder", function (count) { @@ -499,69 +499,69 @@ liberator.Mail = function () //{{{ var c = tree.currentIndex; if (c - count < 0) { - liberator.beep(); + beep(); return; } tree.view.selection.timedSelect(c - count, tree._selectDelay ); }, - { flags: liberator.Mappings.flags.COUNT }); + { flags: Mappings.flags.COUNT }); - liberator.mappings.add(modes, [""], + mappings.add(myModes, [""], "Go to previous mailbox with unread messages", function (count) { selectUnreadFolder(true, count); }, - { flags: liberator.Mappings.flags.COUNT }); + { flags: Mappings.flags.COUNT }); // THREADING - liberator.mappings.add(modes, ["za"], + mappings.add(myModes, ["za"], "Toggle thread collapsed/expanded", - function () { if (!liberator.mail.expandThread()) liberator.mail.collapseThread(); }); + function () { if (!mail.expandThread()) mail.collapseThread(); }); - liberator.mappings.add(modes, ["zc"], + mappings.add(myModes, ["zc"], "Collapse thread", - function () { liberator.mail.collapseThread(); }); + function () { mail.collapseThread(); }); - liberator.mappings.add(modes, ["zo"], + mappings.add(myModes, ["zo"], "Open thread", - function () { liberator.mail.expandThread(); }); + function () { mail.expandThread(); }); - liberator.mappings.add(modes, ["zr", "zR"], + mappings.add(myModes, ["zr", "zR"], "Expand all threads", function () { goDoCommand("cmd_expandAllThreads"); }); - liberator.mappings.add(modes, ["zm", "zM"], + mappings.add(myModes, ["zm", "zM"], "Collapse all threads", function () { goDoCommand("cmd_collapseAllThreads"); }); - liberator.mappings.add(modes, [""], + mappings.add(myModes, [""], "Go forward", function (count) { if (count < 1) count = 1; while (count--) GoNextMessage(nsMsgNavigationType.forward, true); }, - { flags: liberator.Mappings.flags.COUNT }); + { flags: Mappings.flags.COUNT }); - liberator.mappings.add(modes, [""], + mappings.add(myModes, [""], "Go back", function (count) { if (count < 1) count = 1; while (count--) GoNextMessage(nsMsgNavigationType.back, true); }, - { flags: liberator.Mappings.flags.COUNT }); + { flags: Mappings.flags.COUNT }); - liberator.mappings.add(modes, ["gg"], + mappings.add(myModes, ["gg"], "Select first message", function (count) { if (count < 1) count = 1; while (count--) GoNextMessage(nsMsgNavigationType.firstMessage, true); }, - { flags: liberator.Mappings.flags.COUNT }); + { flags: Mappings.flags.COUNT }); - liberator.mappings.add(modes, ["G"], + mappings.add(myModes, ["G"], "Select last message", function (count) { if (count < 1) count = 1; while (count--) GoNextMessage(nsMsgNavigationType.lastMessage, false); }, - { flags: liberator.Mappings.flags.COUNT }); + { flags: Mappings.flags.COUNT }); // tagging messages - liberator.mappings.add(modes, ["l"], + mappings.add(myModes, ["l"], "Label message", function (arg) { if (!GetSelectedMessages()) - return liberator.beep(); + return beep(); switch (arg) { @@ -572,33 +572,33 @@ liberator.Mail = function () //{{{ case "p": ToggleMessageTagKey(3); break; // Personal case "t": ToggleMessageTagKey(4); break; // TODO case "l": ToggleMessageTagKey(5); break; // Later - default: liberator.beep(); + default: beep(); } }, { - flags: liberator.Mappings.flags.ARGUMENT + flags: Mappings.flags.ARGUMENT }); // TODO: change binding? - liberator.mappings.add(modes, ["T"], + mappings.add(myModes, ["T"], "Mark current folder as read", function () { - if (liberator.mail.currentFolder.isServer) - return liberator.beep(); + if (mail.currentFolder.isServer) + return beep(); - liberator.mail.currentFolder.markAllMessagesRead(); + mail.currentFolder.markAllMessagesRead(); }); - liberator.mappings.add(modes, [""], + mappings.add(myModes, [""], "Mark all messages as read", function () { - liberator.mail.getFolders("", false).forEach(function (folder) { folder.markAllMessagesRead(); }); + mail.getFolders("", false).forEach(function (folder) { folder.markAllMessagesRead(); }); }); // DISPLAY OPTIONS - liberator.mappings.add(modes, ["h"], + mappings.add(myModes, ["h"], "Toggle displayed headers", function () { @@ -607,55 +607,55 @@ liberator.Mail = function () //{{{ MsgReload(); }); - liberator.mappings.add(modes, ["x"], + mappings.add(myModes, ["x"], "Toggle HTML message display", function () { var want_html = (gPrefBranch.getIntPref("mailnews.display.html_as", 1) == 1); - liberator.mail.setHTML(want_html ? 1 : 0); + mail.setHTML(want_html ? 1 : 0); }); // YANKING TEXT - liberator.mappings.add(modes, ["Y"], + mappings.add(myModes, ["Y"], "Yank subject", function () { try { var subject = gDBView.hdrForFirstSelectedMessage.mime2DecodedSubject; - liberator.util.copyToClipboard(subject, true); + util.copyToClipboard(subject, true); } - catch (e) { liberator.beep(); } + catch (e) { beep(); } }); - liberator.mappings.add(modes, ["y"], + mappings.add(myModes, ["y"], "Yank sender or feed URL", function () { try { - if (liberator.mail.currentAccount.server.type == "rss") - liberator.util.copyToClipboard(getRSSUrl(), true); + if (mail.currentAccount.server.type == "rss") + util.copyToClipboard(getRSSUrl(), true); else - liberator.util.copyToClipboard(gDBView.hdrForFirstSelectedMessage.mime2DecodedAuthor, true); + util.copyToClipboard(gDBView.hdrForFirstSelectedMessage.mime2DecodedAuthor, true); } - catch (e) { liberator.beep(); } + catch (e) { beep(); } }); // RSS specific mappings - liberator.mappings.add(modes, ["p"], + mappings.add(myModes, ["p"], "Open RSS message in browser", function () { try { - if (liberator.mail.currentAccount.server.type == "rss") + if (mail.currentAccount.server.type == "rss") messenger.launchExternalURL(getRSSUrl()); // TODO: what to do for non-rss message? } catch (e) { - liberator.beep(); + beep(); } }); @@ -663,17 +663,17 @@ liberator.Mail = function () //{{{ ////////////////////// COMMANDS //////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ - liberator.commands.add(["go[to]"], + commands.add(["go[to]"], "Select a folder", function (args, special, count) { args = args || "Inbox"; count = count > 0 ? (count - 1) : 0; - var folder = liberator.mail.getFolders(args, true, true)[count]; + var folder = mail.getFolders(args, true, true)[count]; if (!folder) - liberator.echoerr("Folder \"" + args + "\" does not exist"); - else if (liberator.forceNewTab) + echoerr("Folder \"" + args + "\" does not exist"); + else if (forceNewTab) MsgOpenNewTabForFolder(folder.URI); else SelectFolder(folder.URI); @@ -683,7 +683,7 @@ liberator.Mail = function () //{{{ count: true }); - liberator.commands.add(["m[essage]"], + commands.add(["m[essage]"], "Write a new message", function (args) { @@ -704,38 +704,38 @@ liberator.Mail = function () //{{{ // TODO: is there a better way to check for validity? if (addresses.some(function (recipient) !(/\S@\S+\.\S/.test(recipient)))) { - liberator.echoerr("Exxx: Invalid e-mail address"); + echoerr("Exxx: Invalid e-mail address"); return; } - liberator.mail.composeNewMail(mailargs); + mail.composeNewMail(mailargs); }, { - options: [[["-subject", "-s"], liberator.commands.OPTION_STRING], - [["-attachment", "-a"], liberator.commands.OPTION_LIST], - [["-bcc", "-b"], liberator.commands.OPTION_STRING], - [["-cc", "-c"], liberator.commands.OPTION_STRING], - [["-text", "-t"], liberator.commands.OPTION_STRING]] + options: [[["-subject", "-s"], commands.OPTION_STRING], + [["-attachment", "-a"], commands.OPTION_LIST], + [["-bcc", "-b"], commands.OPTION_STRING], + [["-cc", "-c"], commands.OPTION_STRING], + [["-text", "-t"], commands.OPTION_STRING]] }); - liberator.commands.add(["copy[to]"], + commands.add(["copy[to]"], "Copy selected messages", function (args) { moveOrCopy(true, args); }, { completer: function (filter) getFolderCompletions(filter) }); - liberator.commands.add(["move[to]"], + commands.add(["move[to]"], "Move selected messages", function (args) { moveOrCopy(false, args); }, { completer: function (filter) getFolderCompletions(filter) }); - liberator.commands.add(["empty[trash]"], + commands.add(["empty[trash]"], "Empty trash of the current account", function () { goDoCommand("cmd_emptyTrash"); }, { argCount: "0" }); - liberator.commands.add(["get[messages]"], + commands.add(["get[messages]"], "Check for new messages", - function (args, special) liberator.mail.getNewMessages(!special), + function (args, special) mail.getNewMessages(!special), { argCount: "0", bang: true, @@ -785,10 +785,10 @@ liberator.Mail = function () //{{{ while (args.attachments.length > 0) { var url = args.attachments.pop(); - var file = liberator.io.getFile(url); + var file = io.getFile(url); if (!file.exists()) { - liberator.echoerr("Exxx: Could not attach file `" + url + "'", liberator.commandline.FORCE_SINGLELINE); + echoerr("Exxx: Could not attach file `" + url + "'", commandline.FORCE_SINGLELINE); return; } @@ -848,7 +848,7 @@ liberator.Mail = function () //{{{ } catch (e) { - liberator.log("Error getting messages for account " + account.prettyName + ": " + e); + log("Error getting messages for account " + account.prettyName + ": " + e); } }); }, @@ -1006,7 +1006,7 @@ liberator.Mail = function () //{{{ } catch (e) { - liberator.dump("ERROR: " + folder.prettyName + " failed to getMessages\n"); + dump("ERROR: " + folder.prettyName + " failed to getMessages\n"); continue; } @@ -1031,7 +1031,7 @@ liberator.Mail = function () //{{{ // TODO: finally for the "rest" of the current folder - liberator.beep(); + beep(); }, setHTML: function (value) diff --git a/content/mappings.js b/content/mappings.js index 87295601..506c84fc 100644 --- a/content/mappings.js +++ b/content/mappings.js @@ -27,8 +27,8 @@ the terms of any one of the MPL, the GPL or the LGPL. }}} ***** END LICENSE BLOCK *****/ // Do NOT create instances of this class yourself, use the helper method -// liberator.mappings.add() instead -liberator.Map = function (modes, cmds, description, action, extraInfo) //{{{ +// mappings.add() instead +with (liberator) liberator.Map = function (modes, cmds, description, action, extraInfo) //{{{ { if (!modes || (!cmds || !cmds.length) || !action) return null; @@ -47,7 +47,7 @@ liberator.Map = function (modes, cmds, description, action, extraInfo) //{{{ this.noremap = extraInfo.noremap || false; }; -liberator.Map.prototype = { +with (liberator) liberator.Map.prototype = { hasName: function (name) { @@ -58,23 +58,23 @@ liberator.Map.prototype = { { var args = []; - if (this.flags & liberator.Mappings.flags.MOTION) + if (this.flags & Mappings.flags.MOTION) args.push(motion); - if (this.flags & liberator.Mappings.flags.COUNT) + if (this.flags & Mappings.flags.COUNT) args.push(count); - if (this.flags & liberator.Mappings.flags.ARGUMENT) + if (this.flags & Mappings.flags.ARGUMENT) args.push(argument); let self = this; // FIXME: Kludge. if (this.names[0] != ".") - liberator.mappings.repeat = function () self.action.apply(self, args); + mappings.repeat = function () self.action.apply(self, args); return this.action.apply(this, args); } }; //}}} -liberator.Mappings = function () //{{{ +with (liberator) liberator.Mappings = function () //{{{ { //////////////////////////////////////////////////////////////////////////////// ////////////////////// PRIVATE SECTION ///////////////////////////////////////// @@ -83,7 +83,7 @@ liberator.Mappings = function () //{{{ var main = []; // default mappings var user = []; // user created mappings - for (let mode in liberator.modes) + for (let mode in modes) { main[mode] = []; user[mode] = []; @@ -99,10 +99,10 @@ liberator.Mappings = function () //{{{ { var maps = stack[mode]; - for (let i = 0; i < maps.length; i++) + for (let [,map] in Iterator(maps)) { - if (maps[i].hasName(cmd)) - return maps[i]; + if (map.hasName(cmd)) + return map; } return null; @@ -113,18 +113,15 @@ liberator.Mappings = function () //{{{ var maps = user[mode]; var names; - for (let i = 0; i < maps.length; i++) + for (let [i, map] in Iterator(maps)) { - names = maps[i].names; - for (let j = 0; j < names.length; j++) + for (let [j, name] in Iterator(map.names)) { - if (names[j] == cmd) + if (name == cmd) { - names.splice(j, 1); - - if (names.length == 0) + map.names.splice(j, 1); + if (map.names.length == 0) maps.splice(i, 1); - return; } } @@ -134,7 +131,7 @@ liberator.Mappings = function () //{{{ function expandLeader(keyString) { var leaderRegexp = //i; - var currentLeader = liberator.mappings.getMapLeader(); + var currentLeader = mappings.getMapLeader(); return keyString.replace(leaderRegexp, currentLeader); } @@ -175,7 +172,7 @@ liberator.Mappings = function () //{{{ { if (!args) { - liberator.mappings.list(mode); + mappings.list(mode); return; } @@ -184,17 +181,17 @@ liberator.Mappings = function () //{{{ if (!rhs) // list the mapping { - liberator.mappings.list(mode, expandLeader(lhs)); + mappings.list(mode, expandLeader(lhs)); } else { - for (let index = 0; index < mode.length; index++) + for (let [,m] in Iterator(mode)) { - liberator.mappings.addUserMap([mode[index]], [lhs], + mappings.addUserMap([m], [lhs], "User defined mapping", - function (count) { liberator.events.feedkeys((count > 1 ? count : "") + rhs, noremap); }, + function (count) { events.feedkeys((count > 1 ? count : "") + rhs, noremap); }, { - flags: liberator.Mappings.flags.COUNT, + flags: Mappings.flags.COUNT, rhs: rhs, noremap: noremap }); @@ -204,65 +201,65 @@ liberator.Mappings = function () //{{{ modeDescription = modeDescription ? " in " + modeDescription + " mode" : ""; - liberator.commands.add([ch ? ch + "m[ap]" : "map"], + commands.add([ch ? ch + "m[ap]" : "map"], "Map a key sequence" + modeDescription, function (args) { map(args, modes, false); }, - { completer: function (filter) liberator.completion.userMapping(filter, modes) }); + { completer: function (filter) completion.userMapping(filter, modes) }); - liberator.commands.add([ch + "no[remap]"], + commands.add([ch + "no[remap]"], "Map a key sequence without remapping keys" + modeDescription, function (args) { map(args, modes, true); }); - liberator.commands.add([ch + "mapc[lear]"], + commands.add([ch + "mapc[lear]"], "Remove all mappings" + modeDescription, function () { for (let i = 0; i < modes.length; i++) - liberator.mappings.removeAll(modes[i]); + mappings.removeAll(modes[i]); }, { argCount: "0" }); - liberator.commands.add([ch + "unm[ap]"], + commands.add([ch + "unm[ap]"], "Remove a mapping" + modeDescription, function (args) { if (!args) { - liberator.echoerr("E474: Invalid argument"); + echoerr("E474: Invalid argument"); return; } - var found = false; - for (let i = 0; i < modes.length; i++) + let found = false; + for (let [,mode] in Iterator(modes)) { - if (liberator.mappings.hasMap(modes[i], args)) + if (mappings.hasMap(mode, args)) { - liberator.mappings.remove(modes[i], args); + mappings.remove(mode, args); found = true; } } if (!found) - liberator.echoerr("E31: No such mapping"); + echoerr("E31: No such mapping"); }, - { completer: function (filter) liberator.completion.userMapping(filter, modes) }); + { completer: function (filter) completion.userMapping(filter, modes) }); } /////////////////////////////////////////////////////////////////////////////}}} ////////////////////// COMMANDS //////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ - addMapCommands("", [liberator.modes.NORMAL], ""); - addMapCommands("c", [liberator.modes.COMMAND_LINE], "command line"); - addMapCommands("i", [liberator.modes.INSERT, liberator.modes.TEXTAREA], "insert"); + addMapCommands("", [modes.NORMAL], ""); + addMapCommands("c", [modes.COMMAND_LINE], "command line"); + addMapCommands("i", [modes.INSERT, modes.TEXTAREA], "insert"); if (liberator.has("mail")) - addMapCommands("m", [liberator.modes.MESSAGE], "message"); + addMapCommands("m", [modes.MESSAGE], "message"); /////////////////////////////////////////////////////////////////////////////}}} ////////////////////// PUBLIC SECTION ////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ // FIXME: - liberator.Mappings.flags = { + Mappings.flags = { ALLOW_EVENT_ROUTING: 1 << 0, // if set, return true inside the map command to pass the event further to firefox MOTION: 1 << 1, COUNT: 1 << 2, @@ -274,7 +271,7 @@ liberator.Mappings = function () //{{{ // NOTE: just normal mode for now __iterator__: function () { - return mappingsIterator([liberator.modes.NORMAL], main); + return mappingsIterator([modes.NORMAL], main); }, // used by :mkvimperatorrc to save mappings @@ -285,13 +282,13 @@ liberator.Mappings = function () //{{{ add: function (modes, keys, description, action, extra) { - addMap(new liberator.Map(modes, keys, description, action, extra), false); + addMap(new Map(modes, keys, description, action, extra), false); }, addUserMap: function (modes, keys, description, action, extra) { keys = keys.map(function (key) expandLeader(key)); - var map = new liberator.Map(modes, keys, description || "User defined mapping", action, extra); + var map = new Map(modes, keys, description || "User defined mapping", action, extra); // remove all old mappings to this key sequence for (let i = 0; i < map.names.length; i++) @@ -305,31 +302,30 @@ liberator.Mappings = function () //{{{ get: function (mode, cmd) { - mode = mode || liberator.modes.NORMAL; + mode = mode || modes.NORMAL; return getMap(mode, cmd, user) || getMap(mode, cmd, main); }, getDefault: function (mode, cmd) { - mode = mode || liberator.modes.NORMAL; + mode = mode || modes.NORMAL; return getMap(mode, cmd, main); }, // returns an array of mappings with names which START with "cmd" (but are NOT "cmd") getCandidates: function (mode, cmd) { - var mappings = user[mode].concat(main[mode]); - var matches = []; + let mappings = user[mode].concat(main[mode]); + let matches = []; - for (let i = 0; i < mappings.length; i++) + for (let [,map] in Iterator(mappings)) { - var map = mappings[i]; - for (let j = 0; j < map.names.length; j++) + for (let [,name] in Iterator(map.names)) { - if (map.names[j].indexOf(cmd) == 0 && map.names[j].length > cmd.length) + if (name.indexOf(cmd) == 0 && name.length > cmd.length) { // for < only return a candidate if it doesn't look like a mapping - if (cmd != "<" || !/^<.+>/.test(map.names[j])) + if (cmd != "<" || !/^<.+>/.test(name)) matches.push(map); } } @@ -340,7 +336,7 @@ liberator.Mappings = function () //{{{ getMapLeader: function () { - var leaderRef = liberator.variableReference("mapleader"); + var leaderRef = variableReference("mapleader"); return leaderRef[0] ? leaderRef[0][leaderRef[1]] : "\\"; }, @@ -368,7 +364,7 @@ liberator.Mappings = function () //{{{ if (!maps || maps.length == 0) { - liberator.echo("No mappings found"); + echo("No mappings found"); return; } @@ -398,20 +394,20 @@ liberator.Mappings = function () //{{{ var flag = output.some(function (x) x); if (!flag) { - liberator.echo("No mappings found"); + echo("No mappings found"); return; } var modeSign = ""; modes.forEach(function (mode) { - if (mode == liberator.modes.NORMAL) + if (mode == modes.NORMAL) modeSign += "n"; - if ((mode == liberator.modes.INSERT || mode == liberator.modes.TEXTAREA) && modeSign.indexOf("i") == -1) + if ((mode == modes.INSERT || mode == modes.TEXTAREA) && modeSign.indexOf("i") == -1) modeSign += "i"; - if (mode == liberator.modes.COMMAND_LINE) + if (mode == modes.COMMAND_LINE) modeSign += "c"; - if (mode == liberator.modes.MESSAGRE) + if (mode == modes.MESSAGRE) modeSign += "m"; }); @@ -419,8 +415,8 @@ liberator.Mappings = function () //{{{ if (output[i])); let list = { - liberator.template.map(_maps, function (map) - liberator.template.map(map.names, function (name) + template.map(_maps, function (map) + template.map(map.names, function (name) @@ -428,7 +424,7 @@ liberator.Mappings = function () //{{{ )) }
{modeSign} {name} {map.noremap ? "*" : " "}
; - liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); + commandline.echo(list, commandline.HL_NORMAL, commandline.FORCE_MULTILINE); } }; diff --git a/content/modes.js b/content/modes.js index e7effbdf..c8a02858 100644 --- a/content/modes.js +++ b/content/modes.js @@ -26,7 +26,7 @@ the provisions above, a recipient may use your version of this file under the terms of any one of the MPL, the GPL or the LGPL. }}} ***** END LICENSE BLOCK *****/ -liberator.modes = (function () //{{{ +with (liberator) liberator.modes = (function () //{{{ { //////////////////////////////////////////////////////////////////////////////// ////////////////////// PRIVATE SECTION ///////////////////////////////////////// @@ -50,44 +50,44 @@ liberator.modes = (function () //{{{ return "-- PASS THROUGH --"; var ext = ""; - if (extended & liberator.modes.QUICK_HINT) + if (extended & modes.QUICK_HINT) ext += " (quick)"; - if (extended & liberator.modes.EXTENDED_HINT) + if (extended & modes.EXTENDED_HINT) ext += " (extended)"; - if (extended & liberator.modes.ALWAYS_HINT) + if (extended & modes.ALWAYS_HINT) ext += " (always)"; - if (extended & liberator.modes.INACTIVE_HINT) + if (extended & modes.INACTIVE_HINT) ext += " (inactive)"; - if (extended & liberator.modes.MENU) // TODO: desirable? + if (extended & modes.MENU) // TODO: desirable? ext += " (menu)"; // when recording a macro var macromode = ""; - if (liberator.modes.isRecording) + if (modes.isRecording) macromode = "recording"; - else if (liberator.modes.isReplaying) + else if (modes.isReplaying) macromode = "replaying"; ext += " --" + macromode; switch (main) { - case liberator.modes.INSERT: + case modes.INSERT: return "-- INSERT" + ext; - case liberator.modes.VISUAL: - return (extended & liberator.modes.LINE) ? "-- VISUAL LINE" + ext : "-- VISUAL" + ext; - case liberator.modes.HINTS: + case modes.VISUAL: + return (extended & modes.LINE) ? "-- VISUAL LINE" + ext : "-- VISUAL" + ext; + case modes.HINTS: return "-- HINTS" + ext; - case liberator.modes.CARET: + case modes.CARET: return "-- CARET" + ext; - case liberator.modes.TEXTAREA: + case modes.TEXTAREA: return "-- TEXTAREA" + ext; - case liberator.modes.MESSAGE: + case modes.MESSAGE: return "-- MESSAGE" + ext; - case liberator.modes.COMPOSE: + case modes.COMPOSE: return "-- COMPOSE" + ext; - case liberator.modes.CUSTOM: - return "-- " + liberator.plugins.mode + ext; + case modes.CUSTOM: + return "-- " + plugins.mode + ext; default: // NORMAL mode return macromode; } @@ -95,23 +95,23 @@ liberator.modes = (function () //{{{ // NOTE: Pay attention that you don't run into endless loops // Usually you should only indicate to leave a special mode like HINTS - // by calling liberator.modes.reset() and adding the stuff which is needed + // by calling modes.reset() and adding the stuff which is needed // for its cleanup here function handleModeChange(oldMode, newMode) { // TODO: fix v.log() to work with verbosity level - //liberator.log("switching from mode " + oldMode + " to mode " + newMode, 7); - //liberator.dump("switching from mode " + oldMode + " to mode " + newMode + "\n"); + //log("switching from mode " + oldMode + " to mode " + newMode, 7); + //dump("switching from mode " + oldMode + " to mode " + newMode + "\n"); switch (oldMode) { - case liberator.modes.TEXTAREA: - case liberator.modes.INSERT: - liberator.editor.unselectText(); + case modes.TEXTAREA: + case modes.INSERT: + editor.unselectText(); break; - case liberator.modes.VISUAL: - if (newMode == liberator.modes.CARET) + case modes.VISUAL: + if (newMode == modes.CARET) { // clear any selection made var selection = window.content.getSelection(); @@ -122,31 +122,31 @@ liberator.modes = (function () //{{{ catch (e) {} } else - liberator.editor.unselectText(); + editor.unselectText(); break; - case liberator.modes.CUSTOM: - liberator.plugins.stop(); + case modes.CUSTOM: + plugins.stop(); break; - case liberator.modes.HINTS: - liberator.hints.hide(); + case modes.HINTS: + hints.hide(); break; - case liberator.modes.COMMAND_LINE: - liberator.commandline.close(); + case modes.COMMAND_LINE: + commandline.close(); break; } - if (newMode == liberator.modes.NORMAL) + if (newMode == modes.NORMAL) { // disable caret mode when we want to switch to normal mode - var value = liberator.options.getPref("accessibility.browsewithcaret", false); + var value = options.getPref("accessibility.browsewithcaret", false); if (value) - liberator.options.setPref("accessibility.browsewithcaret", false); + options.setPref("accessibility.browsewithcaret", false); - liberator.statusline.updateUrl(); - liberator.focusContent(false); + statusline.updateUrl(); + focusContent(false); } } @@ -183,13 +183,7 @@ liberator.modes = (function () //{{{ RECORDING: 1 << 21, PROMPT: 1 << 22, - __iterator__: function () - { - var modes = this.all; - - for (let i = 0; i < modes.length; i++) - yield modes[i]; - }, + __iterator__: function () util.arrayIter(this.all), get all() [this.NONE, this.NORMAL, this.INSERT, this.VISUAL, this.HINTS, this.COMMAND_LINE, this.CARET, @@ -198,15 +192,15 @@ liberator.modes = (function () //{{{ // show the current mode string in the command line show: function () { - if (!liberator.options["showmode"]) + if (!options["showmode"]) return; // never show mode messages if we are in command line mode - if (main == liberator.modes.COMMAND_LINE) + if (main == modes.COMMAND_LINE) return; - liberator.commandline.echo(getModeMessage(), liberator.commandline.HL_MODEMSG, - liberator.commandline.DISALLOW_MULTILINE); + commandline.echo(getModeMessage(), commandline.HL_MODEMSG, + commandline.DISALLOW_MULTILINE); }, // add/remove always work on the extended mode only @@ -228,7 +222,7 @@ liberator.modes = (function () //{{{ main = mainMode; if (!extendedMode) - extended = liberator.modes.NONE; + extended = modes.NONE; } if (typeof extendedMode === "number") extended = extendedMode; @@ -255,24 +249,24 @@ liberator.modes = (function () //{{{ setCustomMode: function (modestr, oneventfunc, stopfunc) { // TODO this.plugin[id]... ('id' maybe submode or what..) - liberator.plugins.mode = modestr; - liberator.plugins.onEvent = oneventfunc; - liberator.plugins.stop = stopfunc; + plugins.mode = modestr; + plugins.onEvent = oneventfunc; + plugins.stop = stopfunc; }, // keeps recording state reset: function (silent) { modeStack = []; - if (liberator.config.isComposeWindow) - this.set(liberator.modes.COMPOSE, liberator.modes.NONE, silent); + if (config.isComposeWindow) + this.set(modes.COMPOSE, modes.NONE, silent); else - this.set(liberator.modes.NORMAL, liberator.modes.NONE, silent); + this.set(modes.NORMAL, modes.NONE, silent); }, remove: function (mode) { - extended = (extended | mode) ^ mode; + extended &= ~mode; this.show(); }, @@ -295,7 +289,7 @@ liberator.modes = (function () //{{{ main = value; // setting the main mode always resets any extended mode - extended = liberator.modes.NONE; + extended = modes.NONE; this.show(); }, diff --git a/content/muttator.js b/content/muttator.js index 3e81d687..aa97b9f4 100644 --- a/content/muttator.js +++ b/content/muttator.js @@ -26,7 +26,7 @@ the provisions above, a recipient may use your version of this file under the terms of any one of the MPL, the GPL or the LGPL. }}} ***** END LICENSE BLOCK *****/ -liberator.config = { //{{{ +with (liberator) liberator.config = { //{{{ /*** required options, no checks done if they really exist, so be careful ***/ name: "Muttator", hostApplication: "Thunderbird", // TODO: can this be found out otherwise? gBrandBundle.getString("brandShortName"); @@ -37,7 +37,7 @@ liberator.config = { //{{{ guioptions: { m: ["mail-toolbar-menubar2"], T: ["mail-bar2"], f: ["folderPaneBox", "folderpane_splitter"], F: ["folderPaneHeader"] }, get isComposeWindow() window.wintype == "msgcompose", - get browserModes() [liberator.modes.MESSAGE], + get browserModes() [modes.MESSAGE], // focusContent() focuses this widget get mainWidget() this.isComposeWindow ? document.getElementById("content-frame") : GetThreadTree(), get mainWindowID() this.isComposeWindow ? "msgcomposeWindow" : "messengerWindow", @@ -92,7 +92,7 @@ liberator.config = { //{{{ /*["searchengines", "Manage installed search engines", function () { openDialog("chrome://browser/content/search/engineManager.xul", "_blank", "chrome,dialog,modal,centerscreen"); }], ["selectionsource", "View selection source", - function () { liberator.buffer.viewSelectionSource(); }]*/ + function () { buffer.viewSelectionSource(); }]*/ ], // they are sorted by relevance, not alphabetically @@ -111,7 +111,7 @@ liberator.config = { //{{{ // 0: never automatically edit externally // 1: automatically edit externally when message window is shown the first time // 2: automatically edit externally, once the message text gets focus (not working currently) - liberator.options.add(["autoexternal", "ae"], + options.add(["autoexternal", "ae"], "Edit message with external editor by default", "boolean", false); @@ -119,39 +119,39 @@ liberator.config = { //{{{ if (this.isComposeWindow) { this.features = ["addressbook"]; // the composer has no special features - //liberator.loadModule("addressbook", liberator.Addressbook); + //loadModule("addressbook", Addressbook); // TODO: move mappings elsewhere, probably compose.js - liberator.mappings.add([liberator.modes.COMPOSE], + mappings.add([modes.COMPOSE], ["e"], "Edit message", - function () { liberator.editor.editWithExternalEditor(); }); + function () { editor.editWithExternalEditor(); }); - liberator.mappings.add([liberator.modes.COMPOSE], + mappings.add([modes.COMPOSE], ["y"], "Send message now", function () { goDoCommand("cmd_sendNow"); }); - liberator.mappings.add([liberator.modes.COMPOSE], + mappings.add([modes.COMPOSE], ["Y"], "Send message later", function () { goDoCommand("cmd_sendLater"); }); // FIXME: does not really work reliably - liberator.mappings.add([liberator.modes.COMPOSE], + mappings.add([modes.COMPOSE], ["t"], "Select To: field", function () { awSetFocus(0, awGetInputElement(1)); }); - liberator.mappings.add([liberator.modes.COMPOSE], + mappings.add([modes.COMPOSE], ["s"], "Select Subject: field", function () { GetMsgSubjectElement().focus(); }); - liberator.mappings.add([liberator.modes.COMPOSE], + mappings.add([modes.COMPOSE], ["i"], "Select message body", function () { SetMsgBodyFrameFocus(); }); - liberator.mappings.add([liberator.modes.COMPOSE], + mappings.add([modes.COMPOSE], ["q"], "Close composer, ask when for unsaved changes", function () { DoCommandClose(); }); - liberator.mappings.add([liberator.modes.COMPOSE], + mappings.add([modes.COMPOSE], ["Q", "ZQ"], "Force closing composer", function () { MsgComposeCloseWindow(true); /* cache window for better performance*/ }); @@ -168,10 +168,10 @@ liberator.config = { //{{{ NotifyDocumentStateChanged: function (nowDirty) { // only edit with external editor if this window was not cached! - if (liberator.options["autoexternal"] && !window.messageWasEditedExternally/* && !gMsgCompose.recycledWindow*/) + if (options["autoexternal"] && !window.messageWasEditedExternally/* && !gMsgCompose.recycledWindow*/) { window.messageWasEditedExternally = true; - liberator.editor.editWithExternalEditor(); + editor.editWithExternalEditor(); } }, @@ -195,16 +195,16 @@ liberator.config = { //{{{ }, true); /*window.document.addEventListener("unload", function () { - GetCurrentEditor().removeDocumentStateListener(liberator.config.stateListener); + GetCurrentEditor().removeDocumentStateListener(config.stateListener); }, true);*/ } else { - liberator.loadModule("mail", liberator.Mail); - liberator.loadModule("addressbook", liberator.Addressbook); - liberator.loadModule("tabs", liberator.Tabs); - liberator.loadModule("marks", liberator.Marks); - liberator.loadModule("hints", liberator.Hints); + loadModule("mail", Mail); + loadModule("addressbook", Addressbook); + loadModule("tabs", Tabs); + loadModule("marks", Marks); + loadModule("hints", Hints); } } }; //}}} diff --git a/content/options.js b/content/options.js index c972f0ff..28a85ec7 100644 --- a/content/options.js +++ b/content/options.js @@ -27,8 +27,8 @@ the terms of any one of the MPL, the GPL or the LGPL. }}} ***** END LICENSE BLOCK *****/ // do NOT create instances of this class yourself, use the helper method -// liberator.options.add() instead -liberator.Option = function (names, description, type, defaultValue, extraInfo) //{{{ +// options.add() instead +with (liberator) liberator.Option = function (names, description, type, defaultValue, extraInfo) //{{{ { if (!names || !type) return null; @@ -40,8 +40,8 @@ liberator.Option = function (names, description, type, defaultValue, extraInfo) this.name = cannonName; this.names = names; this.type = type; - this.scope = (extraInfo.scope & liberator.options.OPTION_SCOPE_BOTH) || - liberator.options.OPTION_SCOPE_GLOBAL; + this.scope = (extraInfo.scope & options.OPTION_SCOPE_BOTH) || + options.OPTION_SCOPE_GLOBAL; // XXX set to BOTH by default someday? - kstep this.description = description || ""; @@ -68,8 +68,8 @@ liberator.Option = function (names, description, type, defaultValue, extraInfo) } } - this.__defineGetter__("globalvalue", function () liberator.options.store.get(cannonName)); - this.__defineSetter__("globalvalue", function (val) { liberator.options.store.set(cannonName, val); }); + this.__defineGetter__("globalvalue", function () options.store.get(cannonName)); + this.__defineSetter__("globalvalue", function (val) { options.store.set(cannonName, val); }); if (this.globalvalue == undefined) this.globalvalue = this.defaultValue; @@ -87,9 +87,9 @@ liberator.Option = function (names, description, type, defaultValue, extraInfo) var aValue; - if (liberator.has("tabs") && (scope & liberator.options.OPTION_SCOPE_LOCAL)) - aValue = liberator.tabs.options[this.name]; - if ((scope & liberator.options.OPTION_SCOPE_GLOBAL) && (aValue == undefined)) + if (liberator.has("tabs") && (scope & options.OPTION_SCOPE_LOCAL)) + aValue = tabs.options[this.name]; + if ((scope & options.OPTION_SCOPE_GLOBAL) && (aValue == undefined)) aValue = this.globalvalue; if (this.getter) @@ -112,13 +112,13 @@ liberator.Option = function (names, description, type, defaultValue, extraInfo) if (newValue === undefined) { newValue = tmpValue; - liberator.log("DEPRECATED: '" + this.name + "' setter should return a value"); + log("DEPRECATED: '" + this.name + "' setter should return a value"); } } - if (liberator.has("tabs") && (scope & liberator.options.OPTION_SCOPE_LOCAL)) - liberator.tabs.options[this.name] = newValue; - if ((scope & liberator.options.OPTION_SCOPE_GLOBAL) && newValue != this.globalValue) + if (liberator.has("tabs") && (scope & options.OPTION_SCOPE_LOCAL)) + tabs.options[this.name] = newValue; + if ((scope & options.OPTION_SCOPE_GLOBAL) && newValue != this.globalValue) this.globalvalue = newValue; this.hasChanged = true; @@ -156,7 +156,7 @@ liberator.Option = function (names, description, type, defaultValue, extraInfo) }; //}}} -liberator.Options = function () //{{{ +with (liberator) liberator.Options = function () //{{{ { //////////////////////////////////////////////////////////////////////////////// ////////////////////// PRIVATE SECTION ///////////////////////////////////////// @@ -164,20 +164,20 @@ liberator.Options = function () //{{{ var prefService = Components.classes["@mozilla.org/preferences-service;1"] .getService(Components.interfaces.nsIPrefBranch); - var options = {}; + var optionHash = {}; function optionObserver(key, event, option) { // Trigger any setters. - let opt = liberator.options.get(option); + let opt = options.get(option); if (event == "change" && opt) - opt.set(opt.value, liberator.options.OPTION_SCOPE_GLOBAL) + opt.set(opt.value, options.OPTION_SCOPE_GLOBAL) } - liberator.storage.newMap("options", false); - liberator.storage.addObserver("options", optionObserver); - liberator.registerObserver("shutdown", function () { - liberator.storage.removeObserver("options", optionObserver) + storage.newMap("options", false); + storage.addObserver("options", optionObserver); + registerObserver("shutdown", function () { + storage.removeObserver("options", optionObserver) }); function storePreference(name, value) @@ -189,26 +189,26 @@ liberator.Options = function () //{{{ if (type == prefService.PREF_INVALID || type == prefService.PREF_STRING) prefService.setCharPref(name, value); else if (type == prefService.PREF_INT) - liberator.echoerr("E521: Number required after =: " + name + "=" + value); + echoerr("E521: Number required after =: " + name + "=" + value); else - liberator.echoerr("E474: Invalid argument: " + name + "=" + value); + echoerr("E474: Invalid argument: " + name + "=" + value); break; case "number": if (type == prefService.PREF_INVALID || type == prefService.PREF_INT) prefService.setIntPref(name, value); else - liberator.echoerr("E474: Invalid argument: " + name + "=" + value); + echoerr("E474: Invalid argument: " + name + "=" + value); break; case "boolean": if (type == prefService.PREF_INVALID || type == prefService.PREF_BOOL) prefService.setBoolPref(name, value); else if (type == prefService.PREF_INT) - liberator.echoerr("E521: Number required after =: " + name + "=" + value); + echoerr("E521: Number required after =: " + name + "=" + value); else - liberator.echoerr("E474: Invalid argument: " + name + "=" + value); + echoerr("E474: Invalid argument: " + name + "=" + value); break; default: - liberator.echoerr("Unknown preference type: " + typeof value + " (" + name + "=" + value + ")"); + echoerr("Unknown preference type: " + typeof value + " (" + name + "=" + value + ")"); } } @@ -254,7 +254,7 @@ liberator.Options = function () //{{{ if (!/keypress/.test(popupAllowedEvents)) { storePreference("dom.popup_allowed_events", popupAllowedEvents + " keypress"); - liberator.registerObserver("shutdown", function () + registerObserver("shutdown", function () { if (loadPreference("dom.popup_allowed_events", "") == popupAllowedEvents + " keypress") @@ -275,7 +275,7 @@ liberator.Options = function () //{{{ ////////////////////// COMMANDS //////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ - liberator.commands.add(["let"], + commands.add(["let"], "Set or list a variable", function (args) { @@ -284,7 +284,7 @@ liberator.Options = function () //{{{ var str = { - liberator.template.map(liberator.globalVariables, function ([i, value]) { + template.map(globalVariables, function ([i, value]) { let prefix = typeof value == "number" ? "#" : typeof value == "function" ? "*" : " "; @@ -296,9 +296,9 @@ liberator.Options = function () //{{{ }
; if (str.*.length()) - liberator.echo(str, liberator.commandline.FORCE_MULTILINE); + echo(str, commandline.FORCE_MULTILINE); else - liberator.echo("No variables found"); + echo("No variables found"); return; } @@ -308,17 +308,17 @@ liberator.Options = function () //{{{ { if (!matches[1]) { - var reference = liberator.variableReference(matches[2]); + var reference = variableReference(matches[2]); if (!reference[0] && matches[3]) { - liberator.echoerr("E121: Undefined variable: " + matches[2]); + echoerr("E121: Undefined variable: " + matches[2]); return; } - var expr = liberator.evalExpression(matches[4]); + var expr = evalExpression(matches[4]); if (expr === undefined) { - liberator.echoerr("E15: Invalid expression: " + matches[4]); + echoerr("E15: Invalid expression: " + matches[4]); return; } else @@ -326,7 +326,7 @@ liberator.Options = function () //{{{ if (!reference[0]) { if (reference[2] == "g") - reference[0] = liberator.globalVariables; + reference[0] = globalVariables; else return; // for now } @@ -348,10 +348,10 @@ liberator.Options = function () //{{{ // 1 - name else if (matches = args.match(/^\s*([\w:]+)\s*$/)) { - var reference = liberator.variableReference(matches[1]); + var reference = variableReference(matches[1]); if (!reference[0]) { - liberator.echoerr("E121: Undefined variable: " + matches[1]); + echoerr("E121: Undefined variable: " + matches[1]); return; } @@ -359,19 +359,19 @@ liberator.Options = function () //{{{ let prefix = typeof value == "number" ? "#" : typeof value == "function" ? "*" : " "; - liberator.echo(reference[1] + "\t\t" + prefix + value); + echo(reference[1] + "\t\t" + prefix + value); } }); - liberator.commands.add(["pref[erences]", "prefs"], - "Show " + liberator.config.hostApplication + " preferences", + commands.add(["pref[erences]", "prefs"], + "Show " + config.hostApplication + " preferences", function (args, special) { if (special) // open Firefox settings GUI dialog { - liberator.open("about:config", - (liberator.options["newtab"] && liberator.options.get("newtab").has("all", "prefs")) - ? liberator.NEW_TAB : liberator.CURRENT_TAB); + open("about:config", + (options["newtab"] && options.get("newtab").has("all", "prefs")) + ? NEW_TAB : CURRENT_TAB); } else { @@ -383,34 +383,34 @@ liberator.Options = function () //{{{ bang: true, }); - liberator.commands.add(["setl[ocal]"], + commands.add(["setl[ocal]"], "Set local option", function (args, special, count) { - liberator.commands.get("set").execute(args, special, count, { scope: liberator.options.OPTION_SCOPE_LOCAL }); + commands.get("set").execute(args, special, count, { scope: options.OPTION_SCOPE_LOCAL }); }, { bang: true, count: true, completer: function (filter, special, count) { - return liberator.commands.get("set").completer(filter, special, count, { scope: liberator.options.OPTION_SCOPE_LOCAL }); + return commands.get("set").completer(filter, special, count, { scope: options.OPTION_SCOPE_LOCAL }); } } ); - liberator.commands.add(["setg[lobal]"], + commands.add(["setg[lobal]"], "Set global option", function (args, special, count) { - liberator.commands.get("set").execute(args, special, count, { scope: liberator.options.OPTION_SCOPE_GLOBAL }); + commands.get("set").execute(args, special, count, { scope: options.OPTION_SCOPE_GLOBAL }); }, { bang: true, count: true, completer: function (filter, special, count) { - return liberator.commands.get("set").completer(filter, special, count, { scope: liberator.options.OPTION_SCOPE_GLOBAL }); + return commands.get("set").completer(filter, special, count, { scope: options.OPTION_SCOPE_GLOBAL }); } } ); @@ -432,7 +432,7 @@ liberator.Options = function () //{{{ } if (matches) - ret.option = liberator.options.get(ret.name, ret.scope); + ret.option = options.get(ret.name, ret.scope); ret.prefix = prefix; ret.postfix = postfix; @@ -469,7 +469,7 @@ liberator.Options = function () //{{{ } // TODO: support setting multiple options at once - liberator.commands.add(["se[t]"], + commands.add(["se[t]"], "Set an option", function (args, special, count, modifiers) { @@ -488,13 +488,13 @@ liberator.Options = function () //{{{ let invertBoolean = (postfix == "!"); if (name == "all" && reset) - liberator.echoerr("You can't reset all options, it could make " + liberator.config.hostApplication + " unusable."); + echoerr("You can't reset all options, it could make " + config.hostApplication + " unusable."); else if (name == "all") - liberator.options.listPrefs(onlyNonDefault, ""); + options.listPrefs(onlyNonDefault, ""); else if (reset) - liberator.options.resetPref(name); + options.resetPref(name); else if (invertBoolean) - liberator.options.invertPref(name); + options.invertPref(name); else if (valueGiven) { switch (value) @@ -512,11 +512,11 @@ liberator.Options = function () //{{{ if (/^\d+$/.test(value)) value = parseInt(value, 10); } - liberator.options.setPref(name, value); + options.setPref(name, value); } else { - liberator.options.listPrefs(onlyNonDefault, name); + options.listPrefs(onlyNonDefault, name); } return; } @@ -524,14 +524,14 @@ liberator.Options = function () //{{{ let opt = parseOpt(args, modifiers); if (!opt) { - liberator.echoerr("Error parsing :set command: " + args); + echoerr("Error parsing :set command: " + args); return; } let option = opt.option; if (option == null && !opt.all) { - liberator.echoerr("No such option: " + opt.name); + echoerr("No such option: " + opt.name); return; } @@ -540,7 +540,7 @@ liberator.Options = function () //{{{ { if (opt.all) { - for (let option in liberator.options) + for (let option in options) option.reset(); } else @@ -553,14 +553,14 @@ liberator.Options = function () //{{{ { if (opt.all) { - liberator.options.list(opt.onlyNonDefault, opt.scope); + options.list(opt.onlyNonDefault, opt.scope); } else { if (option.type == "boolean") - liberator.echo((opt.optionValue ? " " : "no") + option.name); + echo((opt.optionValue ? " " : "no") + option.name); else - liberator.echo(" " + option.name + "=" + opt.optionValue); + echo(" " + option.name + "=" + opt.optionValue); } } // write access @@ -576,7 +576,7 @@ liberator.Options = function () //{{{ case "boolean": if (opt.valueGiven) { - liberator.echoerr("E474: Invalid argument: " + args); + echoerr("E474: Invalid argument: " + args); return; } @@ -592,7 +592,7 @@ liberator.Options = function () //{{{ if (isNaN(value)) { - liberator.echoerr("E521: Number required after =: " + args); + echoerr("E521: Number required after =: " + args); return; } @@ -619,11 +619,11 @@ liberator.Options = function () //{{{ switch (opt.operator) { case "+": - newValue = liberator.util.uniq(Array.concat(opt.optionHas, opt.valueHas), true); + newValue = util.uniq(Array.concat(opt.optionHas, opt.valueHas), true); break; case "^": // NOTE: Vim doesn't prepend if there's a match in the current value - newValue = liberator.util.uniq(Array.concat(opt.valueHas, opt.optionHas), true); + newValue = util.uniq(Array.concat(opt.valueHas, opt.optionHas), true); break; case "-": newValue = opt.optionHas.filter(function (item) opt.valueHas.indexOf(item) == -1); @@ -662,7 +662,7 @@ liberator.Options = function () //{{{ break; default: - liberator.echoerr("E685: Internal error: option type `" + option.type + "' not supported"); + echoerr("E685: Internal error: option type `" + option.type + "' not supported"); } if (option.isValidValue(newValue)) @@ -671,7 +671,7 @@ liberator.Options = function () //{{{ } else // FIXME: need to be able to specify more specific errors - liberator.echoerr("E474: Invalid argument: " + args); + echoerr("E474: Invalid argument: " + args); } }, { @@ -696,7 +696,7 @@ liberator.Options = function () //{{{ { if (name.match("^" + filter.substr(0, filter.length - 1) + "$" )) { - let value = liberator.options.getPref(name) + ""; + let value = options.getPref(name) + ""; return [filter.length + 1, [[value, ""]]]; } } @@ -704,36 +704,36 @@ liberator.Options = function () //{{{ } optionCompletions = prefArray.map(function (pref) - [pref, liberator.options.getPref(pref)]); + [pref, options.getPref(pref)]); - return [0, liberator.completion.filter(optionCompletions, filter)]; + return [0, completion.filter(optionCompletions, filter)]; } let prefix = (filter.match(/^(no|inv)/) || [""])[0]; if (prefix) filter = filter.substr(prefix.length); - let scope = modifiers && modifiers.scope || liberator.options.OPTION_SCOPE_BOTH; + let scope = modifiers && modifiers.scope || options.OPTION_SCOPE_BOTH; - let options = (opt for (opt in liberator.options) - if ((opt.scope & scope) && (!prefix || opt.type == "boolean" || prefix == "inv" && /list$/.test(opt.type)))); + let opts = (opt for (opt in options) + if ((opt.scope & scope) && (!prefix || opt.type == "boolean" || prefix == "inv" && /list$/.test(opt.type)))); if (!filter) { let opts = [[prefix + option.name, option.description] - for (option in options)]; + for (option in opts)]; return [0, opts]; } else if (filter.indexOf("=") == -1) { - for (let option in options) + for (let option in opts) optionCompletions.push([[prefix + name, option.description] for each (name in option.names) if (name.indexOf(filter) == 0)]); // Flatten array. optionCompletions = Array.concat.apply(Array, optionCompletions); - return [0, liberator.completion.filter(optionCompletions, prefix + filter, true)]; + return [0, completion.filter(optionCompletions, prefix + filter, true)]; } else if (prefix == "no") return; @@ -790,11 +790,11 @@ liberator.Options = function () //{{{ } } } - return [len, liberator.completion.filter(completions, filter, true)]; + return [len, completion.filter(completions, filter, true)]; } }); - liberator.commands.add(["unl[et]"], + commands.add(["unl[et]"], "Delete a variable", function (args, special) { @@ -806,11 +806,11 @@ liberator.Options = function () //{{{ for (let i = 0; i < args.arguments.length; i++) { var name = args.arguments[i]; - var reference = liberator.variableReference(name); + var reference = variableReference(name); if (!reference[0]) { if (!special) - liberator.echoerr("E108: No such variable: " + name); + echoerr("E108: No such variable: " + name); return; } @@ -834,8 +834,7 @@ liberator.Options = function () //{{{ __iterator__: function () { - let sorted = [o for ([,o] in Iterator(options))] - .sort(function (a, b) String.localeCompare(a.name, b.name)); + let sorted = [o for ([i, o] in Iterator(optionHash))].sort(function (a, b) String.localeCompare(a.name, b.name)); return (v for ([k, v] in Iterator(sorted))); }, @@ -844,38 +843,38 @@ liberator.Options = function () //{{{ if (!extraInfo) extraInfo = {}; - var option = new liberator.Option(names, description, type, defaultValue, extraInfo); + let option = new Option(names, description, type, defaultValue, extraInfo); if (!option) return false; - if (option.name in options) + if (option.name in optionHash) { // never replace for now - liberator.log("Warning: '" + names[0] + "' already exists, NOT replacing existing option.", 1); + log("Warning: '" + names[0] + "' already exists, NOT replacing existing option.", 1); return false; } - // quickly access options with liberator.options["wildmode"]: + // quickly access options with options["wildmode"]: this.__defineGetter__(option.name, function () option.value); this.__defineSetter__(option.name, function (value) { option.value = value; }); - options[option.name] = option; + optionHash[option.name] = option; return true; }, get: function (name, scope) { if (!scope) - scope = liberator.options.OPTION_SCOPE_BOTH; + scope = options.OPTION_SCOPE_BOTH; - if (name in options && (options[name].scope & scope)) - return options[name]; + if (name in optionHash) + return (optionHash[name].scope & scope) && optionHash[name]; - for (let [,opt] in Iterator(options)) + for (let opt in Iterator(options)) { - if (opt.hasName(name) && (opt.scope & scope)) - return opt; + if (opt.hasName(name)) + return (opt.scope & scope) && opt; } return null; @@ -884,10 +883,10 @@ liberator.Options = function () //{{{ list: function (onlyNonDefault, scope) { if (!scope) - scope = liberator.options.OPTION_SCOPE_BOTH; + scope = options.OPTION_SCOPE_BOTH; let opts = function (opt) { - for (let opt in Iterator(liberator.options)) + for (let opt in Iterator(options)) { let option = { isDefault: opt.value == opt.defaultValue, @@ -910,14 +909,14 @@ liberator.Options = function () //{{{ } else { - option.value = <>={liberator.template.highlight(opt.value)}; + option.value = <>={template.highlight(opt.value)}; } yield option; } } - let list = liberator.template.options("Options", opts()); - liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); + let list = template.options("Options", opts()); + commandline.echo(list, commandline.HL_NORMAL, commandline.FORCE_MULTILINE); }, listPrefs: function (onlyNonDefault, filter) @@ -934,14 +933,14 @@ liberator.Options = function () //{{{ if (onlyNonDefault && !userValue || pref.indexOf(filter) == -1) continue; - value = liberator.options.getPref(pref); + value = options.getPref(pref); if (typeof value == "string") value = value.substr(0, 100).replace(/\n/g, " "); let option = { isDefault: !userValue, default: loadPreference(pref, null, true), - value: <>={liberator.template.highlight(value)}, + value: <>={template.highlight(value)}, name: pref, pre: "  ", /* Unicode nonbreaking space. */ }; @@ -950,11 +949,11 @@ liberator.Options = function () //{{{ } } - let list = liberator.template.options(liberator.config.hostApplication + " Options", prefs()); - liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); + let list = template.options(config.hostApplication + " Options", prefs()); + commandline.echo(list, commandline.HL_NORMAL, commandline.FORCE_MULTILINE); }, - get store() liberator.storage.options, + get store() storage.options, getPref: function (name, forcedDefault) { @@ -977,7 +976,7 @@ liberator.Options = function () //{{{ if (prefService.getPrefType(name) == prefService.PREF_BOOL) this.setPref(name, !this.getPref(name)); else - liberator.echoerr("E488: Trailing characters: " + name + "!"); + echoerr("E488: Trailing characters: " + name + "!"); } }; //}}} diff --git a/content/tabs.js b/content/tabs.js index 487c783b..e9802b6c 100644 --- a/content/tabs.js +++ b/content/tabs.js @@ -28,7 +28,7 @@ the terms of any one of the MPL, the GPL or the LGPL. // TODO: many methods do not work with Thunderbird correctly yet -liberator.Tabs = function () //{{{ +with (liberator) liberator.Tabs = function () //{{{ { //////////////////////////////////////////////////////////////////////////////// ////////////////////// PRIVATE SECTION ///////////////////////////////////////// @@ -36,7 +36,7 @@ liberator.Tabs = function () //{{{ var tabmail; var getBrowser = (function () { - if (liberator.config.hostApplication == "Thunderbird") + if (config.hostApplication == "Thunderbird") { return function () { @@ -107,37 +107,37 @@ liberator.Tabs = function () //{{{ } // hide tabs initially - if (liberator.config.name == "Vimperator") + if (config.name == "Vimperator") getBrowser().mStrip.getElementsByClassName("tabbrowser-tabs")[0].collapsed = true; /////////////////////////////////////////////////////////////////////////////}}} ////////////////////// OPTIONS ///////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ - liberator.options.add(["showtabline", "stal"], + options.add(["showtabline", "stal"], "Control when to show the tab bar of opened web pages", - "number", liberator.config.name == "Vimperator" ? 2 : 0, + "number", config.name == "Vimperator" ? 2 : 0, { setter: function (value) { - var tabs = liberator.tabs.tabStrip; + let tabStrip = tabs.tabStrip; - if (!tabs) + if (!tabStrip) return; if (value == 0) { - tabs.collapsed = true; + tabStrip.collapsed = true; } else if (value == 1) { - liberator.options.setPref("browser.tabs.autoHide", true); - tabs.collapsed = false; + options.setPref("browser.tabStrip.autoHide", true); + tabStrip.collapsed = false; } else { - liberator.options.setPref("browser.tabs.autoHide", false); - tabs.collapsed = false; + options.setPref("browser.tabStrip.autoHide", false); + tabStrip.collapsed = false; } return value; @@ -153,9 +153,9 @@ liberator.Tabs = function () //{{{ validator: function (value) value >= 0 && value <= 2 }); - if (liberator.config.name == "Vimperator") + if (config.name == "Vimperator") { - liberator.options.add(["activate", "act"], + options.add(["activate", "act"], "Define when tabs are automatically activated", "stringlist", "homepage,quickmark,tabopen,paste", { @@ -176,7 +176,7 @@ liberator.Tabs = function () //{{{ } }); - liberator.options.add(["newtab"], + options.add(["newtab"], "Define which commands should output in a new tab by default", "stringlist", "", { @@ -199,7 +199,7 @@ liberator.Tabs = function () //{{{ } }); - liberator.options.add(["popups", "pps"], + options.add(["popups", "pps"], "Where to show requested popup windows", "number", 1, { @@ -211,8 +211,8 @@ liberator.Tabs = function () //{{{ [1, 2], // always in new window [2, 1]];// current tab unless it has specified sizes - liberator.options.setPref("browser.link.open_newwindow.restriction", values[value][0]); - liberator.options.setPref("browser.link.open_newwindow", values[value][1]); + options.setPref("browser.link.open_newwindow.restriction", values[value][0]); + options.setPref("browser.link.open_newwindow", values[value][1]); return value; }, @@ -234,76 +234,76 @@ liberator.Tabs = function () //{{{ ////////////////////// MAPPINGS //////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ - liberator.mappings.add([liberator.modes.NORMAL], ["g0", "g^"], + mappings.add([modes.NORMAL], ["g0", "g^"], "Go to the first tab", - function (count) { liberator.tabs.select(0); }); + function (count) { tabs.select(0); }); - liberator.mappings.add([liberator.modes.NORMAL], ["g$"], + mappings.add([modes.NORMAL], ["g$"], "Go to the last tab", - function (count) { liberator.tabs.select("$"); }); + function (count) { tabs.select("$"); }); - liberator.mappings.add([liberator.modes.NORMAL], ["gt", "", "", ""], + mappings.add([modes.NORMAL], ["gt", "", "", ""], "Go to the next tab", - function (count) { liberator.tabs.select(count > 0 ? count - 1: "+1", count > 0 ? false : true); }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { tabs.select(count > 0 ? count - 1: "+1", count > 0 ? false : true); }, + { flags: Mappings.flags.COUNT }); - liberator.mappings.add([liberator.modes.NORMAL], ["gT", "", "", ""], + mappings.add([modes.NORMAL], ["gT", "", "", ""], "Go to previous tab", - function (count) { liberator.tabs.select("-" + (count < 1 ? 1 : count), true); }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { tabs.select("-" + (count < 1 ? 1 : count), true); }, + { flags: Mappings.flags.COUNT }); - if (liberator.config.name == "Vimperator") + if (config.name == "Vimperator") { - liberator.mappings.add([liberator.modes.NORMAL], ["b"], + mappings.add([modes.NORMAL], ["b"], "Open a prompt to switch buffers", - function () { liberator.commandline.open(":", "buffer! ", liberator.modes.EX); }); + function () { commandline.open(":", "buffer! ", modes.EX); }); - liberator.mappings.add([liberator.modes.NORMAL], ["B"], + mappings.add([modes.NORMAL], ["B"], "Show buffer list", - function () { liberator.tabs.list(false); }); + function () { tabs.list(false); }); - liberator.mappings.add([liberator.modes.NORMAL], ["d"], + mappings.add([modes.NORMAL], ["d"], "Delete current buffer", - function (count) { liberator.tabs.remove(getBrowser().mCurrentTab, count, false, 0); }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { tabs.remove(getBrowser().mCurrentTab, count, false, 0); }, + { flags: Mappings.flags.COUNT }); - liberator.mappings.add([liberator.modes.NORMAL], ["D"], + mappings.add([modes.NORMAL], ["D"], "Delete current buffer, focus tab to the left", - function (count) { liberator.tabs.remove(getBrowser().mCurrentTab, count, true, 0); }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { tabs.remove(getBrowser().mCurrentTab, count, true, 0); }, + { flags: Mappings.flags.COUNT }); - liberator.mappings.add([liberator.modes.NORMAL], ["gb"], + mappings.add([modes.NORMAL], ["gb"], "Repeat last :buffer[!] command", - function (count) { liberator.tabs.switchTo(null, null, count, false); }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { tabs.switchTo(null, null, count, false); }, + { flags: Mappings.flags.COUNT }); - liberator.mappings.add([liberator.modes.NORMAL], ["gB"], + mappings.add([modes.NORMAL], ["gB"], "Repeat last :buffer[!] command in reverse direction", - function (count) { liberator.tabs.switchTo(null, null, count, true); }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { tabs.switchTo(null, null, count, true); }, + { flags: Mappings.flags.COUNT }); - liberator.mappings.add([liberator.modes.NORMAL], ["u"], + mappings.add([modes.NORMAL], ["u"], "Undo closing of a tab", - function (count) { liberator.commands.get("undo").execute("", false, count); }, - { flags: liberator.Mappings.flags.COUNT }); + function (count) { commands.get("undo").execute("", false, count); }, + { flags: Mappings.flags.COUNT }); - liberator.mappings.add([liberator.modes.NORMAL], ["", ""], + mappings.add([modes.NORMAL], ["", ""], "Select the alternate tab or the [count]th tab", function (count) { if (count < 1) - liberator.tabs.selectAlternateTab(); + tabs.selectAlternateTab(); else - liberator.tabs.switchTo(count.toString(), false); + tabs.switchTo(count.toString(), false); }, - { flags: liberator.Mappings.flags.COUNT }); + { flags: Mappings.flags.COUNT }); } /////////////////////////////////////////////////////////////////////////////}}} ////////////////////// COMMANDS //////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ - liberator.commands.add(["bd[elete]", "bw[ipeout]", "bun[load]", "tabc[lose]"], + commands.add(["bd[elete]", "bw[ipeout]", "bun[load]", "tabc[lose]"], "Delete current buffer", function (args, special, count) { @@ -314,7 +314,7 @@ liberator.Tabs = function () //{{{ var match; if (match = args.match(/^(\d+):?/)) { - liberator.tabs.remove(liberator.tabs.getTab(parseInt(match[1], 10) - 1)); + tabs.remove(tabs.getTab(parseInt(match[1], 10) - 1)); removed = 1; } else @@ -329,47 +329,47 @@ liberator.Tabs = function () //{{{ if (host.indexOf(args) >= 0 || uri == args || (special && (title.indexOf(args) >= 0 || uri.indexOf(args) >= 0))) { - liberator.tabs.remove(liberator.tabs.getTab(i)); + tabs.remove(tabs.getTab(i)); removed++; } } } if (removed > 0) - liberator.echo(removed + " fewer tab(s)"); + echo(removed + " fewer tab(s)"); else - liberator.echoerr("E94: No matching tab for " + args); + echoerr("E94: No matching tab for " + args); } else // just remove the current tab - liberator.tabs.remove(getBrowser().mCurrentTab, count > 0 ? count : 1, special, 0); + tabs.remove(getBrowser().mCurrentTab, count > 0 ? count : 1, special, 0); }, { bang: true, count: true, - completer: function (filter) liberator.completion.buffer(filter) + completer: function (filter) completion.buffer(filter) }); // TODO: this should open in a new tab positioned directly after the current one, not at the end - liberator.commands.add(["tab"], + commands.add(["tab"], "Execute a command and tell it to output in a new tab", function (args) { liberator.forceNewTab = true; - liberator.execute(args.string); + execute(args.string); liberator.forceNewTab = false; }, { argCount: "+", - completer: function (filter) liberator.completion.ex(filter) + completer: function (filter) completion.ex(filter) }); - liberator.commands.add(["tabl[ast]", "bl[ast]"], + commands.add(["tabl[ast]", "bl[ast]"], "Switch to the last tab", - function () liberator.tabs.select("$", false), + function () tabs.select("$", false), { argCount: "0" }); // TODO: "Zero count" if 0 specified as arg - liberator.commands.add(["tabp[revious]", "tp[revious]", "tabN[ext]", "tN[ext]", "bp[revious]", "bN[ext]"], + commands.add(["tabp[revious]", "tp[revious]", "tabN[ext]", "tN[ext]", "bp[revious]", "bN[ext]"], "Switch to the previous tab or go [count] tabs back", function (args, special, count) { @@ -377,23 +377,23 @@ liberator.Tabs = function () //{{{ if (args) { if (/^\d+$/.test(args)) - liberator.tabs.select("-" + args, true); // FIXME: urgh! + tabs.select("-" + args, true); // FIXME: urgh! else - liberator.echoerr("E488: Trailing characters"); + echoerr("E488: Trailing characters"); } else if (count > 0) { - liberator.tabs.select("-" + count, true); + tabs.select("-" + count, true); } else { - liberator.tabs.select("-1", true); + tabs.select("-1", true); } }, { count: true }); // TODO: "Zero count" if 0 specified as arg - liberator.commands.add(["tabn[ext]", "tn[ext]", "bn[ext]"], + commands.add(["tabn[ext]", "tn[ext]", "bn[ext]"], "Switch to the next or [count]th tab", function (args, special, count) { @@ -410,7 +410,7 @@ liberator.Tabs = function () //{{{ } else { - liberator.echoerr("E488: Trailing characters"); + echoerr("E488: Trailing characters"); return; } } @@ -419,27 +419,27 @@ liberator.Tabs = function () //{{{ index = count - 1; } - if (index < liberator.tabs.count) - liberator.tabs.select(index, true); + if (index < tabs.count) + tabs.select(index, true); else - liberator.beep(); + beep(); } else { - liberator.tabs.select("+1", true); + tabs.select("+1", true); } }, { count: true }); - liberator.commands.add(["tabr[ewind]", "tabfir[st]", "br[ewind]", "bf[irst]"], + commands.add(["tabr[ewind]", "tabfir[st]", "br[ewind]", "bf[irst]"], "Switch to the first tab", - function () { liberator.tabs.select(0, false); }, + function () { tabs.select(0, false); }, { argCount: "0" }); - if (liberator.config.name == "Vimperator") + if (config.name == "Vimperator") { // TODO: "Zero count" if 0 specified as arg, multiple args and count ranges? - liberator.commands.add(["b[uffer]"], + commands.add(["b[uffer]"], "Switch to a buffer", function (args, special, count) { @@ -448,108 +448,108 @@ liberator.Tabs = function () //{{{ if (args && count > 0) { if (/^\d+$/.test(args)) - liberator.tabs.switchTo(args, special); + tabs.switchTo(args, special); else - liberator.echoerr("E488: Trailing characters"); + echoerr("E488: Trailing characters"); } else if (count > 0) { - liberator.tabs.switchTo(count.toString(), special); + tabs.switchTo(count.toString(), special); } else { - liberator.tabs.switchTo(args, special); + tabs.switchTo(args, special); } }, { bang: true, count: true, - completer: function (filter) liberator.completion.buffer(filter) + completer: function (filter) completion.buffer(filter) }); - liberator.commands.add(["buffers", "files", "ls", "tabs"], + commands.add(["buffers", "files", "ls", "tabs"], "Show a list of all buffers", - function (args) { liberator.tabs.list(); }, + function (args) { tabs.list(); }, { argCount: "0" }); - liberator.commands.add(["quita[ll]", "qa[ll]"], - "Quit " + liberator.config.name, - function (args, special) { liberator.quit(false, special); }, + commands.add(["quita[ll]", "qa[ll]"], + "Quit " + config.name, + function (args, special) { quit(false, special); }, { argCount: "0", bang: true }); - liberator.commands.add(["reloada[ll]"], + commands.add(["reloada[ll]"], "Reload all tab pages", - function (args, special) { liberator.tabs.reloadAll(special); }, + function (args, special) { tabs.reloadAll(special); }, { argCount: "0", bang: true }); // TODO: add count support - liberator.commands.add(["tabm[ove]"], + commands.add(["tabm[ove]"], "Move the current tab after tab N", function (args, special) { // FIXME: tabmove! N should probably produce an error if (!/^([+-]?\d+|)$/.test(args)) { - liberator.echoerr("E488: Trailing characters"); + echoerr("E488: Trailing characters"); return; } if (!args) args = "$"; // if not specified, move to the last tab - liberator.tabs.move(getBrowser().mCurrentTab, args, special); + tabs.move(getBrowser().mCurrentTab, args, special); }, { bang: true }); - liberator.commands.add(["tabo[nly]"], + commands.add(["tabo[nly]"], "Close all other tabs", - function () { liberator.tabs.keepOnly(getBrowser().mCurrentTab); }, + function () { tabs.keepOnly(getBrowser().mCurrentTab); }, { argCount: "0" }); - liberator.commands.add(["tabopen", "t[open]", "tabnew", "tabe[dit]"], + commands.add(["tabopen", "t[open]", "tabnew", "tabe[dit]"], "Open one or more URLs in a new tab", function (args, special) { - var where = special ? liberator.NEW_TAB : liberator.NEW_BACKGROUND_TAB; - if (/\btabopen\b/.test(liberator.options["activate"])) - where = special ? liberator.NEW_BACKGROUND_TAB : liberator.NEW_TAB; + var where = special ? NEW_TAB : NEW_BACKGROUND_TAB; + if (/\btabopen\b/.test(options["activate"])) + where = special ? NEW_BACKGROUND_TAB : NEW_TAB; if (args) - liberator.open(args, where); + open(args, where); else - liberator.open("about:blank", where); + open("about:blank", where); }, { bang: true, - completer: function (filter) liberator.completion.url(filter) + completer: function (filter) completion.url(filter) }); - liberator.commands.add(["tabde[tach]"], + commands.add(["tabde[tach]"], "Detach current tab to its own window", - function () { liberator.tabs.detachTab(null); }, + function () { tabs.detachTab(null); }, { argCount: "0" }); - liberator.commands.add(["tabd[uplicate]"], + commands.add(["tabd[uplicate]"], "Duplicate current tab", function (args, special, count) { - var tab = liberator.tabs.getTab(); + var tab = tabs.getTab(); var activate = special ? true : false; - if (/\btabopen\b/.test(liberator.options["activate"])) + if (/\btabopen\b/.test(options["activate"])) activate = !activate; if (count < 1) count = 1; for (let i = 0; i < count; i++) - liberator.tabs.cloneTab(tab, activate); + tabs.cloneTab(tab, activate); }, { argCount: "0", @@ -561,7 +561,7 @@ liberator.Tabs = function () //{{{ if (liberator.has("session")) { // TODO: extract common functionality of "undoall" - liberator.commands.add(["u[ndo]"], + commands.add(["u[ndo]"], "Undo closing of a tab", function (args, special, count) { @@ -596,7 +596,7 @@ liberator.Tabs = function () //{{{ { var url = undoItems[i].state.entries[0].url; var title = undoItems[i].title; - if (liberator.completion.match([url, title], filter, false)) + if (completion.match([url, title], filter, false)) completions.push([url, title]); } return [0, completions]; @@ -604,7 +604,7 @@ liberator.Tabs = function () //{{{ count: true }); - liberator.commands.add(["undoa[ll]"], + commands.add(["undoa[ll]"], "Undo closing of all closed tabs", function (args, special, count) { @@ -620,9 +620,9 @@ liberator.Tabs = function () //{{{ count: true }); - liberator.commands.add(["wqa[ll]", "wq", "xa[ll]"], + commands.add(["wqa[ll]", "wq", "xa[ll]"], "Save the session and quit", - function () { liberator.quit(true); }, + function () { quit(true); }, { argCount: "0" }); } @@ -655,9 +655,9 @@ liberator.Tabs = function () //{{{ get tabStrip() { - if (liberator.config.hostApplication == "Firefox") + if (config.hostApplication == "Firefox") return getBrowser().mStrip.getElementsByClassName("tabbrowser-tabs")[0]; - else if (liberator.config.hostApplication == "Thunderbird") + else if (config.hostApplication == "Thunderbird") return getBrowser().mStrip; }, @@ -715,14 +715,14 @@ liberator.Tabs = function () //{{{ // TODO: shouldn't that have a filter argument? list: function () { - // TODO: move this to liberator.tabs.get() + // TODO: move this to tabs.get() let items = - for (let [i, item] in Iterator(liberator.completion.buffer("")[1])) + for (let [i, item] in Iterator(completion.buffer("")[1])) { - if (i == liberator.tabs.index()) + if (i == tabs.index()) indicator = "%" - else if (i == liberator.tabs.index(liberator.tabs.alternate)) + else if (i == tabs.index(tabs.alternate)) indicator = "#"; else indicator = " "; @@ -737,8 +737,8 @@ liberator.Tabs = function () //{{{ ; } - let list = liberator.template.generic(items); - liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); + let list = template.generic(items); + commandline.echo(list, commandline.HL_NORMAL, commandline.FORCE_MULTILINE); }, // wrap causes the movement to wrap around the start and end of the tab list @@ -760,14 +760,14 @@ liberator.Tabs = function () //{{{ getBrowser().removeTab(tab); else { - if (liberator.buffer.URL != "about:blank" || + if (buffer.URL != "about:blank" || getWebNavigation().sessionHistory.count > 0) { - liberator.open("about:blank", liberator.NEW_BACKGROUND_TAB); + open("about:blank", NEW_BACKGROUND_TAB); getBrowser().removeTab(tab); } else - liberator.beep(); + beep(); } }, Thunderbird: function (tab) @@ -775,19 +775,19 @@ liberator.Tabs = function () //{{{ if (getBrowser().mTabs.length > 1) getBrowser().removeTab(tab); else - liberator.beep(); + beep(); } - }[liberator.config.hostApplication] || function () {}; + }[config.hostApplication] || function () {}; if (typeof count != "number" || count < 1) count = 1; if (quitOnLastTab >= 1 && getBrowser().mTabs.length <= count) { - if (liberator.windows.length > 1) + if (windows.length > 1) window.close(); else - liberator.quit(quitOnLastTab == 2); + quit(quitOnLastTab == 2); return; } @@ -825,7 +825,7 @@ liberator.Tabs = function () //{{{ // FIXME: if (index === -1) { - liberator.beep(); // XXX: move to ex-handling? + beep(); // XXX: move to ex-handling? return; } getBrowser().mTabContainer.selectedIndex = index; @@ -890,7 +890,7 @@ liberator.Tabs = function () //{{{ if (buffer == "#") { - liberator.tabs.selectAlternateTab(); + tabs.selectAlternateTab(); return; } @@ -902,13 +902,13 @@ liberator.Tabs = function () //{{{ var match; if (match = buffer.match(/^(\d+):?/)) { - liberator.tabs.select(parseInt(match[1], 10) - 1, false); // make it zero-based + tabs.select(parseInt(match[1], 10) - 1, false); // make it zero-based return; } var matches = []; var lowerBuffer = buffer.toLowerCase(); - var first = liberator.tabs.index() + (reverse ? 0 : 1); + var first = tabs.index() + (reverse ? 0 : 1); for (let i = 0; i < getBrowser().browsers.length; i++) { var index = (i + first) % getBrowser().browsers.length; @@ -916,7 +916,7 @@ liberator.Tabs = function () //{{{ var title = getBrowser().getBrowserAtIndex(index).contentDocument.title.toLowerCase(); if (url == buffer) { - liberator.tabs.select(index, false); + tabs.select(index, false); return; } @@ -924,9 +924,9 @@ liberator.Tabs = function () //{{{ matches.push(index); } if (matches.length == 0) - liberator.echoerr("E94: No matching buffer for " + buffer); + echoerr("E94: No matching buffer for " + buffer); else if (matches.length > 1 && !allowNonUnique) - liberator.echoerr("E93: More than one match for " + buffer); + echoerr("E93: More than one match for " + buffer); else { if (reverse) @@ -938,7 +938,7 @@ liberator.Tabs = function () //{{{ else index = (count - 1) % matches.length; - liberator.tabs.select(matches[index], false); + tabs.select(matches[index], false); } }, @@ -969,23 +969,23 @@ liberator.Tabs = function () //{{{ selectAlternateTab: function () { - if (liberator.tabs.alternate == null || liberator.tabs.getTab() == liberator.tabs.alternate) + if (tabs.alternate == null || tabs.getTab() == tabs.alternate) { - liberator.echoerr("E23: No alternate page"); + echoerr("E23: No alternate page"); return; } // NOTE: this currently relies on v.tabs.index() returning the // currently selected tab index when passed null - var index = liberator.tabs.index(liberator.tabs.alternate); + var index = tabs.index(tabs.alternate); // TODO: since a tab close is more like a bdelete for us we // should probably reopen the closed tab when a 'deleted' // alternate is selected if (index == -1) - liberator.echoerr("E86: Buffer does not exist"); // TODO: This should read "Buffer N does not exist" + echoerr("E86: Buffer does not exist"); // TODO: This should read "Buffer N does not exist" else - liberator.tabs.select(index); + tabs.select(index); }, // NOTE: when restarting a session FF selects the first tab and then the diff --git a/content/template.js b/content/template.js index ccc081a6..65b8ce71 100644 --- a/content/template.js +++ b/content/template.js @@ -1,12 +1,12 @@ -liberator.template = { +with (liberator) liberator.template = { add: function (a, b) a + b, join: function (c) function (a, b) a + c + b, map: function (iter, fn, sep) { if (iter.length) /* Kludge? */ - iter = liberator.util.arrayIter(iter); + iter = util.arrayIter(iter); let ret = <>; let n = 0; for each (let i in Iterator(iter)) @@ -46,7 +46,7 @@ liberator.template = { return {arg}; case "string": if (processStrings) - arg = <>{liberator.util.escapeString(arg)}; + arg = <>{util.escapeString(arg)}; return {arg}; case "boolean": return {arg}; @@ -107,7 +107,7 @@ liberator.template = { generic: function (xml) { - return <>:{liberator.commandline.getCommand()}
+ xml; + return <>:{commandline.getCommand()}
+ xml; }, bookmarks: function (header, items) @@ -120,14 +120,14 @@ liberator.template = { { this.map(items, function (item) - + - + ) }
{liberator.util.clip(item.title, 50)}{util.clip(item.title, 50)} {item.url}  { !(item.extra && item.extra.length) ? "" : ({ - liberator.template.map(item.extra, function (e) + template.map(item.extra, function (e) <>{e[0]}: {e[1]}, /* Non-breaking space */) }) @@ -188,7 +188,7 @@ liberator.template = { this.map(data, function (datum)
{datum[0]}{liberator.template.maybeXML(datum[1])}{template.maybeXML(datum[1])}
; @@ -211,7 +211,7 @@ liberator.template = { this.map(iter, function (row) { - liberator.template.map(Iterator(row), function ([i, d]) + template.map(Iterator(row), function ([i, d]) {d}) } ) diff --git a/content/ui.js b/content/ui.js index cf81e998..7f472605 100644 --- a/content/ui.js +++ b/content/ui.js @@ -32,7 +32,7 @@ the terms of any one of the MPL, the GPL or the LGPL. * it consists of a prompt and command field * be sure to only create objects of this class when the chrome is ready */ -liberator.CommandLine = function () //{{{ +with (liberator) liberator.CommandLine = function () //{{{ { //////////////////////////////////////////////////////////////////////////////// ////////////////////// PRIVATE SECTION ///////////////////////////////////////// @@ -40,13 +40,13 @@ liberator.CommandLine = function () //{{{ const UNINITIALIZED = -2; // notifies us, if we need to start history/tab-completion from the beginning - liberator.storage.newArray("history-search", true); - liberator.storage.newArray("history-command", true); + storage.newArray("history-search", true); + storage.newArray("history-command", true); - var history = { - get mode() (liberator.modes.extended == liberator.modes.EX) ? "command" : "search", + var inputHistory = { + get mode() (modes.extended == modes.EX) ? "command" : "search", - get store() liberator.storage["history-" + this.mode], + get store() storage["history-" + this.mode], get length() this.store.length, @@ -59,7 +59,7 @@ liberator.CommandLine = function () //{{{ this.store.mutate('filter', function (line) line != str); this.store.push(str); - this.store.truncate(liberator.options["history"], true); + this.store.truncate(options["history"], true); } }; @@ -70,7 +70,7 @@ liberator.CommandLine = function () //{{{ _messages: [], get messages() { - let max = liberator.options["messages"]; + let max = options["messages"]; // resize if 'messages' has changed if (this._messages.length > max) @@ -86,7 +86,7 @@ liberator.CommandLine = function () //{{{ if (!message) return; - if (this._messages.length >= liberator.options["messages"]) + if (this._messages.length >= options["messages"]) this._messages.shift(); this._messages.push(message); @@ -94,7 +94,7 @@ liberator.CommandLine = function () //{{{ }; var lastMowOutput = null; - var completionList = new liberator.ItemList("liberator-completions"); + var completionList = new ItemList("liberator-completions"); var completions = []; // for the example command "open sometext| othertext" (| is the cursor pos): var completionStartIndex = 0; // will be 5 because we want to complete arguments for the :open command @@ -105,13 +105,13 @@ liberator.CommandLine = function () //{{{ var wildIndex = 0; // keep track how often we press in a row var startHints = false; // whether we're waiting to start hints mode - var statusTimer = new liberator.util.Timer(5, 100, function () - liberator.statusline.updateProgress("match " + (completionIndex + 1) + " of " + completions.length)); - var autocompleteTimer = new liberator.util.Timer(201, 300, function (command) { - if (liberator.modes.isReplaying) + var statusTimer = new util.Timer(5, 100, function () + statusline.updateProgress("match " + (completionIndex + 1) + " of " + completions.length)); + var autocompleteTimer = new util.Timer(201, 300, function (command) { + if (modes.isReplaying) return; - let [start, compl] = liberator.completion.ex(command); - liberator.commandline.setCompletions(compl, start); + let [start, compl] = completion.ex(command); + commandline.setCompletions(compl, start); }); // the containing box for the promptWidget and commandWidget @@ -145,8 +145,8 @@ liberator.CommandLine = function () //{{{ var promptCallback = null; var promptCompleter = null; - liberator.registerCallback("change", liberator.modes.EX, function (command) { - if (liberator.options.get("wildoptions").has("auto")) + registerCallback("change", modes.EX, function (command) { + if (options.get("wildoptions").has("auto")) autocompleteTimer.tell(command); else completionIndex = UNINITIALIZED; @@ -157,13 +157,13 @@ liberator.CommandLine = function () //{{{ let callback = promptCallback; promptCallback = null; currentExtendedMode = null; - liberator.commandline.clear(); + commandline.clear(); if (callback) callback(value); } - liberator.registerCallback("cancel", liberator.modes.PROMPT, closePrompt); - liberator.registerCallback("submit", liberator.modes.PROMPT, closePrompt); - liberator.registerCallback("complete", liberator.modes.PROMPT, + registerCallback("cancel", modes.PROMPT, closePrompt); + registerCallback("submit", modes.PROMPT, closePrompt); + registerCallback("complete", modes.PROMPT, function (str) { if (promptCompleter) return promptCompleter(str); }); function setHighlightGroup(group) @@ -185,7 +185,7 @@ liberator.CommandLine = function () //{{{ { promptWidget.collapsed = true; } - promptWidget.setAttribute("class", highlightGroup || liberator.commandline.HL_NORMAL); + promptWidget.setAttribute("class", highlightGroup || commandline.HL_NORMAL); } // sets the command - e.g. 'tabopen', 'open http://example.com/' @@ -216,7 +216,7 @@ liberator.CommandLine = function () //{{{ * after interpolated data. */ XML.ignoreWhitespace = typeof str == "xml"; - var output =
{liberator.template.maybeXML(str)}
; + var output =
{template.maybeXML(str)}
; XML.ignoreWhiteSpace = true; lastMowOutput = output; @@ -226,7 +226,7 @@ liberator.CommandLine = function () //{{{ if (outputContainer.collapsed) doc.body.innerHTML = ""; - doc.body.appendChild(liberator.util.xmlToDom(output, doc)); + doc.body.appendChild(util.xmlToDom(output, doc)); var availableHeight = 250; try @@ -241,27 +241,27 @@ liberator.CommandLine = function () //{{{ outputContainer.height = height + "px"; outputContainer.collapsed = false; - if (liberator.options["more"] && win.scrollMaxY > 0) + if (options["more"] && win.scrollMaxY > 0) { // start the last executed command's output at the top of the screen var elements = doc.getElementsByClassName("ex-command-output"); elements[elements.length - 1].scrollIntoView(true); if (win.scrollY >= win.scrollMaxY) - setLine("Press ENTER or type command to continue", liberator.commandline.HL_QUESTION); + setLine("Press ENTER or type command to continue", commandline.HL_QUESTION); else - setLine("-- More --", liberator.commandline.HL_QUESTION); + setLine("-- More --", commandline.HL_QUESTION); } else { win.scrollTo(0, contentHeight); - setLine("Press ENTER or type command to continue", liberator.commandline.HL_QUESTION); + setLine("Press ENTER or type command to continue", commandline.HL_QUESTION); } win.focus(); startHints = false; - liberator.modes.push(liberator.modes.COMMAND_LINE, liberator.modes.OUTPUT_MULTILINE); + modes.push(modes.COMMAND_LINE, modes.OUTPUT_MULTILINE); } function autosizeMultilineInputWidget() @@ -282,18 +282,18 @@ liberator.CommandLine = function () //{{{ try { - arg = liberator.eval(arg); + arg = eval(arg); } catch (e) { - liberator.echoerr(e); + echoerr(e); return null; } if (typeof arg === "object") - arg = liberator.util.objectToString(arg, useColor); + arg = util.objectToString(arg, useColor); else if (typeof arg === "function") - arg = liberator.util.escapeHTML(arg.toString()); + arg = util.escapeHTML(arg.toString()); else if (typeof arg === "number" || typeof arg === "boolean") arg = "" + arg; else if (typeof arg === "undefined") @@ -307,7 +307,7 @@ liberator.CommandLine = function () //{{{ /////////////////////////////////////////////////////////////////////////////{{{ // TODO: doesn't belong in ui.js - liberator.options.add(["complete", "cpt"], + options.add(["complete", "cpt"], "Items which are completed at the :[tab]open prompt", "charlist", "sfbh", { @@ -325,25 +325,25 @@ liberator.CommandLine = function () //{{{ validator: function (value) !/[^sfbhSl]/.test(value) }); - liberator.options.add(["history", "hi"], + options.add(["history", "hi"], "Number of Ex commands and search patterns to store in the command-line history", "number", 500, { validator: function (value) value >= 0 }); - liberator.options.add(["messages", "msgs"], + options.add(["messages", "msgs"], "Number of messages to store in the message history", "number", 100, { validator: function (value) value >= 0 }); - liberator.options.add(["more"], + options.add(["more"], "Pause the message list window when more than one screen of listings is displayed", "boolean", true); - liberator.options.add(["showmode", "smd"], + options.add(["showmode", "smd"], "Show the current mode in the command line", "boolean", true); - liberator.options.add(["suggestengines"], + options.add(["suggestengines"], "Engine Alias which has a feature of suggest", "stringlist", "google", { @@ -368,7 +368,7 @@ liberator.CommandLine = function () //{{{ } }); - liberator.options.add(["wildignore", "wig"], + options.add(["wildignore", "wig"], "List of file patterns to ignore when completing files", "stringlist", "", { @@ -387,7 +387,7 @@ liberator.CommandLine = function () //{{{ } }); - liberator.options.add(["wildmode", "wim"], + options.add(["wildmode", "wim"], "Define how command line completion works", "stringlist", "list:full", { @@ -410,7 +410,7 @@ liberator.CommandLine = function () //{{{ } }); - liberator.options.add(["wildoptions", "wop"], + options.add(["wildoptions", "wop"], "Change how command line completion is done", "stringlist", "", { @@ -431,37 +431,37 @@ liberator.CommandLine = function () //{{{ ////////////////////// MAPPINGS //////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ - var modes = [liberator.modes.COMMAND_LINE]; + var myModes = [modes.COMMAND_LINE]; // TODO: move "", ""], "Focus content", - function () { liberator.events.onEscape(); }); + function () { events.onEscape(); }); - liberator.mappings.add(modes, + mappings.add(myModes, [""], "Expand command line abbreviation", function () { - liberator.commandline.resetCompletions(); - return liberator.editor.expandAbbreviation("c"); + commandline.resetCompletions(); + return editor.expandAbbreviation("c"); }, - { flags: liberator.Mappings.flags.ALLOW_EVENT_ROUTING }); + { flags: Mappings.flags.ALLOW_EVENT_ROUTING }); - liberator.mappings.add(modes, + mappings.add(myModes, ["", ""], "Expand command line abbreviation", - function () { liberator.editor.expandAbbreviation("c"); }); + function () { editor.expandAbbreviation("c"); }); // FIXME: Should be "g<" but that doesn't work unless it has a non-null // rhs, getCandidates broken? - liberator.mappings.add([liberator.modes.NORMAL], + mappings.add([modes.NORMAL], ["gm"], "Redisplay the last command output", function () { if (lastMowOutput) - liberator.commandline.echo(lastMowOutput, - liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); + commandline.echo(lastMowOutput, + commandline.HL_NORMAL, commandline.FORCE_MULTILINE); else - liberator.beep(); + beep(); }); /////////////////////////////////////////////////////////////////////////////}}} @@ -472,22 +472,22 @@ liberator.CommandLine = function () //{{{ { name: "ec[ho]", description: "Display a string at the bottom of the window", - action: liberator.echo + action: echo }, { name: "echoe[rr]", description: "Display an error string at the bottom of the window", - action: liberator.echoerr + action: echoerr }, { name: "echom[sg]", description: "Display a message at the bottom of the window saving it in the message history", - action: liberator.echomsg + action: echomsg } ]; echoCommands.forEach(function (command) { - liberator.commands.add([command.name], + commands.add([command.name], command.description, function (args) { @@ -495,10 +495,10 @@ liberator.CommandLine = function () //{{{ if (str != null) command.action(str); }, - { completer: function (filter) liberator.completion.javascript(filter) }); + { completer: function (filter) completion.javascript(filter) }); }); - liberator.commands.add(["mes[sages]"], + commands.add(["mes[sages]"], "Display previously given messages", function () { @@ -508,7 +508,7 @@ liberator.CommandLine = function () //{{{ if (messageHistory.length == 1) { let message = messageHistory.messages[0]; - liberator.commandline.echo(message.str, message.highlight, liberator.commandline.FORCE_SINGLELINE); + commandline.echo(message.str, message.highlight, commandline.FORCE_SINGLELINE); } else if (messageHistory.length > 1) { @@ -517,7 +517,7 @@ liberator.CommandLine = function () //{{{ for (let [,message] in Iterator(messageHistory.messages)) list +=
{message.str}
; - liberator.echo(list, liberator.commandline.FORCE_MULTILINE); + echo(list, commandline.FORCE_MULTILINE); } }, { argCount: "0" }); @@ -547,7 +547,7 @@ liberator.CommandLine = function () //{{{ get autocompleteTimer() autocompleteTimer, - get mode() (liberator.modes.extended == liberator.modes.EX) ? "cmd" : "search", + get mode() (modes.extended == modes.EX) ? "cmd" : "search", getCommand: function () { @@ -565,7 +565,7 @@ liberator.CommandLine = function () //{{{ historyIndex = UNINITIALIZED; completionIndex = UNINITIALIZED; - liberator.modes.push(liberator.modes.COMMAND_LINE, currentExtendedMode); + modes.push(modes.COMMAND_LINE, currentExtendedMode); setHighlightGroup(this.HL_NORMAL); setPrompt(currentPrompt); setCommand(currentCommand); @@ -574,17 +574,17 @@ liberator.CommandLine = function () //{{{ // open the completion list automatically if wanted if (/\s/.test(cmd) && - liberator.options.get("wildoptions").has("auto") >= 0 && - extendedMode == liberator.modes.EX) + options.get("wildoptions").has("auto") >= 0 && + extendedMode == modes.EX) autocompleteTimer.tell(cmd); }, // normally used when pressing esc, does not execute a command close: function () { - var res = liberator.triggerCallback("cancel", currentExtendedMode); - history.add(this.getCommand()); - liberator.statusline.updateProgress(""); // we may have a "match x of y" visible + var res = triggerCallback("cancel", currentExtendedMode); + inputHistory.add(this.getCommand()); + statusline.updateProgress(""); // we may have a "match x of y" visible this.clear(); }, @@ -600,7 +600,7 @@ liberator.CommandLine = function () //{{{ setLine("", this.HL_NORMAL); }, - // liberator.echo uses different order of flags as it omits the hightlight group, change v.commandline.echo argument order? --mst + // echo uses different order of flags as it omits the hightlight group, change v.commandline.echo argument order? --mst echo: function (str, highlightGroup, flags) { var focused = document.commandDispatcher.focusedElement; @@ -643,15 +643,15 @@ liberator.CommandLine = function () //{{{ }, // this will prompt the user for a string - // liberator.commandline.input("(s)ave or (o)pen the file?") + // commandline.input("(s)ave or (o)pen the file?") input: function (prompt, callback, extra) { extra = extra || {}; promptCallback = callback; promptCompleter = extra.completer; - liberator.modes.push(liberator.modes.COMMAND_LINE, liberator.modes.PROMPT); - currentExtendedMode = liberator.modes.PROMPT; + modes.push(modes.COMMAND_LINE, modes.PROMPT); + currentExtendedMode = modes.PROMPT; setPrompt(prompt + " ", this.HL_QUESTION); setCommand(extra.default || ""); commandWidget.focus(); @@ -662,7 +662,7 @@ liberator.CommandLine = function () //{{{ inputMultiline: function (untilRegexp, callbackFunc) { // save the mode, because we need to restore it - liberator.modes.push(liberator.modes.COMMAND_LINE, liberator.modes.INPUT_MULTILINE); + modes.push(modes.COMMAND_LINE, modes.INPUT_MULTILINE); // save the arguments, they are needed in the event handler onEvent multilineRegexp = untilRegexp; @@ -683,9 +683,9 @@ liberator.CommandLine = function () //{{{ { // prevent losing focus, there should be a better way, but it just didn't work otherwise setTimeout(function () { - if (liberator.mode == liberator.modes.COMMAND_LINE && - !(liberator.modes.extended & liberator.modes.INPUT_MULTILINE) && - !(liberator.modes.extended & liberator.modes.OUTPUT_MULTILINE)) + if (mode == modes.COMMAND_LINE && + !(modes.extended & modes.INPUT_MULTILINE) && + !(modes.extended & modes.OUTPUT_MULTILINE)) commandWidget.inputField.focus(); }, 0); } @@ -696,38 +696,38 @@ liberator.CommandLine = function () //{{{ } else if (event.type == "input") { - liberator.triggerCallback("change", currentExtendedMode, command); + triggerCallback("change", currentExtendedMode, command); } else if (event.type == "keypress") { if (!currentExtendedMode) return true; - var key = liberator.events.toString(event); - //liberator.log("command line handling key: " + key + "\n"); + var key = events.toString(event); + //log("command line handling key: " + key + "\n"); // user pressed ENTER to carry out a command // user pressing ESCAPE is handled in the global onEscape // FIXME: should trigger "cancel" event - if (liberator.events.isAcceptKey(key)) + if (events.isAcceptKey(key)) { - var mode = currentExtendedMode; // save it here, as setMode() resets it + let mode = currentExtendedMode; // save it here, as setMode() resets it currentExtendedMode = null; /* Don't let modes.pop trigger "cancel" */ - history.add(command); - liberator.modes.pop(true); + inputHistory.add(command); + modes.pop(true); autocompleteTimer.reset(); completionList.hide(); - liberator.focusContent(false); - liberator.statusline.updateProgress(""); // we may have a "match x of y" visible - return liberator.triggerCallback("submit", mode, command); + focusContent(false); + statusline.updateProgress(""); // we may have a "match x of y" visible + return triggerCallback("submit", mode, command); } // user pressed UP or DOWN arrow to cycle history completion else if (/^(|||||)$/.test(key)) { function gotoHistoryItem(index) { - setCommand(history.get(historyIndex)); - liberator.triggerCallback("change", currentExtendedMode, liberator.commandline.getCommand()); + setCommand(inputHistory.get(historyIndex)); + triggerCallback("change", currentExtendedMode, commandline.getCommand()); } let previousItem = /Up/.test(key); @@ -742,21 +742,21 @@ liberator.CommandLine = function () //{{{ // save 'start' position for iterating through the history if (historyIndex == UNINITIALIZED) { - historyIndex = history.length; + historyIndex = inputHistory.length; historyStart = command; } // search the history for the first item matching the current // commandline string - while (historyIndex >= -1 && historyIndex <= history.length) + while (historyIndex >= -1 && historyIndex <= inputHistory.length) { previousItem ? historyIndex-- : historyIndex++; // user pressed DOWN when there is no newer history item - if (historyIndex == history.length) + if (historyIndex == inputHistory.length) { setCommand(historyStart); - liberator.triggerCallback("change", currentExtendedMode, this.getCommand()); + triggerCallback("change", currentExtendedMode, this.getCommand()); break; } @@ -764,19 +764,19 @@ liberator.CommandLine = function () //{{{ if (historyIndex <= -1) { historyIndex = 0; - liberator.beep(); + beep(); break; } - else if (historyIndex >= history.length + 1) + else if (historyIndex >= inputHistory.length + 1) { - historyIndex = history.length; - liberator.beep(); + historyIndex = inputHistory.length; + beep(); break; } if (matchCurrent) { - if (history.get(historyIndex).indexOf(historyStart) == 0) + if (inputHistory.get(historyIndex).indexOf(historyStart) == 0) { gotoHistoryItem(historyIndex); break; @@ -796,7 +796,7 @@ liberator.CommandLine = function () //{{{ historyIndex = UNINITIALIZED; // TODO: call just once, and not on each - var wim = liberator.options["wildmode"].split(","); + var wim = options["wildmode"].split(","); var hasList = false; var longest = false; var full = false; @@ -815,12 +815,12 @@ liberator.CommandLine = function () //{{{ completionIndex = -1; completionPrefix = command.substring(0, commandWidget.selectionStart); completionPostfix = command.substring(commandWidget.selectionStart); - var res = liberator.triggerCallback("complete", currentExtendedMode, completionPrefix); + var res = triggerCallback("complete", currentExtendedMode, completionPrefix); if (res) [completionStartIndex, completions] = res; // sort the completion list - if (liberator.options.get("wildoptions").has("sort")) + if (options.get("wildoptions").has("sort")) completions.sort(function (a, b) String.localeCompare(a[0], b[0])); completionList.setItems(completions); @@ -828,7 +828,7 @@ liberator.CommandLine = function () //{{{ if (completions.length == 0) { - liberator.beep(); + beep(); // prevent tab from moving to the next field: event.preventDefault(); event.stopPropagation(); @@ -867,7 +867,7 @@ liberator.CommandLine = function () //{{{ { var compl = null; if (longest && completions.length > 1) - compl = liberator.completion.getLongestSubstring(); + compl = completion.getLongestSubstring(); else if (full) compl = completions[completionIndex][0]; else if (completions.length == 1) @@ -878,7 +878,7 @@ liberator.CommandLine = function () //{{{ setCommand(command.substring(0, completionStartIndex) + compl + completionPostfix); commandWidget.selectionStart = commandWidget.selectionEnd = completionStartIndex + compl.length; if (longest) - liberator.triggerCallback("change", currentExtendedMode, this.getCommand()); + triggerCallback("change", currentExtendedMode, this.getCommand()); // Start a new completion in the next iteration. Useful for commands like :source // RFC: perhaps the command can indicate whether the completion should be restarted @@ -900,8 +900,8 @@ liberator.CommandLine = function () //{{{ // and blur the command line if there is no text left if (command.length == 0) { - liberator.triggerCallback("cancel", currentExtendedMode); - liberator.modes.pop(); // FIXME: use mode stack + triggerCallback("cancel", currentExtendedMode); + modes.pop(); // FIXME: use mode stack } } else // any other key @@ -916,27 +916,27 @@ liberator.CommandLine = function () //{{{ { if (event.type == "keypress") { - var key = liberator.events.toString(event); - if (liberator.events.isAcceptKey(key)) + var key = events.toString(event); + if (events.isAcceptKey(key)) { var text = multilineInputWidget.value.substr(0, multilineInputWidget.selectionStart); if (text.match(multilineRegexp)) { text = text.replace(multilineRegexp, ""); - liberator.modes.pop(); + modes.pop(); multilineInputWidget.collapsed = true; multilineCallback.call(this, text); } } - else if (liberator.events.isCancelKey(key)) + else if (events.isCancelKey(key)) { - liberator.modes.pop(); + modes.pop(); multilineInputWidget.collapsed = true; } } else if (event.type == "blur") { - if (liberator.modes.extended & liberator.modes.INPUT_MULTILINE) + if (modes.extended & modes.INPUT_MULTILINE) setTimeout(function () { multilineInputWidget.inputField.focus(); }, 0); } else if (event.type == "input") @@ -960,13 +960,13 @@ liberator.CommandLine = function () //{{{ function isScrollable() !win.scrollMaxY == 0; function atEnd() win.scrollY / win.scrollMaxY >= 1; - var key = liberator.events.toString(event); + var key = events.toString(event); if (startHints) { - liberator.statusline.updateInputBuffer(""); + statusline.updateInputBuffer(""); startHints = false; - liberator.hints.show(liberator.modes.EXTENDED_HINT, key, undefined, win); + hints.show(modes.EXTENDED_HINT, key, undefined, win); return; } @@ -977,13 +977,13 @@ liberator.CommandLine = function () //{{{ break; // handled globally in events.js:onEscape() case ":": - liberator.commandline.open(":", "", liberator.modes.EX); + commandline.open(":", "", modes.EX); return; // down a line case "j": case "": - if (liberator.options["more"] && isScrollable()) + if (options["more"] && isScrollable()) win.scrollByLines(1); else passEvent = true; @@ -992,7 +992,7 @@ liberator.CommandLine = function () //{{{ case "": case "": case "": - if (liberator.options["more"] && isScrollable() && !atEnd()) + if (options["more"] && isScrollable() && !atEnd()) win.scrollByLines(1); else closeWindow = true; // don't propagate the event for accept keys @@ -1002,9 +1002,9 @@ liberator.CommandLine = function () //{{{ case "k": case "": case "": - if (liberator.options["more"] && isScrollable()) + if (options["more"] && isScrollable()) win.scrollByLines(-1); - else if (liberator.options["more"] && !isScrollable()) + else if (options["more"] && !isScrollable()) showMorePrompt = true; else passEvent = true; @@ -1012,7 +1012,7 @@ liberator.CommandLine = function () //{{{ // half page down case "d": - if (liberator.options["more"] && isScrollable()) + if (options["more"] && isScrollable()) win.scrollBy(0, win.innerHeight / 2); else passEvent = true; @@ -1022,22 +1022,22 @@ liberator.CommandLine = function () //{{{ case "": if (event.originalTarget.className == "hl-URL buffer-list") { - liberator.tabs.select(parseInt(event.originalTarget.parentNode.parentNode.firstChild.textContent, 10) - 1); + tabs.select(parseInt(event.originalTarget.parentNode.parentNode.firstChild.textContent, 10) - 1); closeWindow = true; break; } else if (event.originalTarget.localName.toLowerCase() == "a") { - liberator.open(event.originalTarget.textContent); + open(event.originalTarget.textContent); break; } case "": // for those not owning a 3-button mouse case "": if (event.originalTarget.localName.toLowerCase() == "a") { - var where = /\btabopen\b/.test(liberator.options["activate"]) ? - liberator.NEW_TAB : liberator.NEW_BACKGROUND_TAB; - liberator.open(event.originalTarget.textContent, where); + var where = /\btabopen\b/.test(options["activate"]) ? + NEW_TAB : NEW_BACKGROUND_TAB; + open(event.originalTarget.textContent, where); } break; @@ -1049,7 +1049,7 @@ liberator.CommandLine = function () //{{{ // page down case "f": - if (liberator.options["more"] && isScrollable()) + if (options["more"] && isScrollable()) win.scrollByPages(1); else passEvent = true; @@ -1057,7 +1057,7 @@ liberator.CommandLine = function () //{{{ case "": case "": - if (liberator.options["more"] && isScrollable() && !atEnd()) + if (options["more"] && isScrollable() && !atEnd()) win.scrollByPages(1); else passEvent = true; @@ -1066,7 +1066,7 @@ liberator.CommandLine = function () //{{{ // half page up case "u": // if (more and scrollable) - if (liberator.options["more"] && isScrollable()) + if (options["more"] && isScrollable()) win.scrollBy(0, -(win.innerHeight / 2)); else passEvent = true; @@ -1074,16 +1074,16 @@ liberator.CommandLine = function () //{{{ // page up case "b": - if (liberator.options["more"] && isScrollable()) + if (options["more"] && isScrollable()) win.scrollByPages(-1); - else if (liberator.options["more"] && !isScrollable()) + else if (options["more"] && !isScrollable()) showMorePrompt = true; else passEvent = true; break; case "": - if (liberator.options["more"] && isScrollable()) + if (options["more"] && isScrollable()) win.scrollByPages(-1); else passEvent = true; @@ -1091,9 +1091,9 @@ liberator.CommandLine = function () //{{{ // top of page case "g": - if (liberator.options["more"] && isScrollable()) + if (options["more"] && isScrollable()) win.scrollTo(0, 0); - else if (liberator.options["more"] && !isScrollable()) + else if (options["more"] && !isScrollable()) showMorePrompt = true; else passEvent = true; @@ -1101,7 +1101,7 @@ liberator.CommandLine = function () //{{{ // bottom of page case "G": - if (liberator.options["more"] && isScrollable() && !atEnd()) + if (options["more"] && isScrollable() && !atEnd()) win.scrollTo(0, win.scrollMaxY); else passEvent = true; @@ -1109,7 +1109,7 @@ liberator.CommandLine = function () //{{{ // copy text to clipboard case "": - liberator.util.copyToClipboard(win.getSelection()); + util.copyToClipboard(win.getSelection()); break; // close the window @@ -1118,13 +1118,13 @@ liberator.CommandLine = function () //{{{ break; case ";": - liberator.statusline.updateInputBuffer(";"); + statusline.updateInputBuffer(";"); startHints = true; break; // unmapped key default: - if (!liberator.options["more"] || !isScrollable() || atEnd() || liberator.events.isCancelKey(key)) + if (!options["more"] || !isScrollable() || atEnd() || events.isCancelKey(key)) passEvent = true; else showMoreHelpPrompt = true; @@ -1133,17 +1133,17 @@ liberator.CommandLine = function () //{{{ if (passEvent || closeWindow) { // FIXME: use mode stack - liberator.modes.pop(); + modes.pop(); this.clear(); if (passEvent) - liberator.events.onKeyPress(event); + events.onKeyPress(event); } else // set update the prompt string { if (showMoreHelpPrompt) setLine("-- More -- SPACE/d/j: screen/page/line down, b/u/k: up, q: quit", this.HL_MOREMSG); - else if (showMorePrompt || (liberator.options["more"] && isScrollable() && !atEnd())) + else if (showMorePrompt || (options["more"] && isScrollable() && !atEnd())) setLine("-- More --", this.HL_MOREMSG); else setLine("Press ENTER or type command to continue", this.HL_QUESTION); @@ -1153,7 +1153,7 @@ liberator.CommandLine = function () //{{{ // to allow asynchronous adding of completions setCompletions: function (compl, start) { - if (liberator.mode != liberator.modes.COMMAND_LINE) + if (mode != modes.COMMAND_LINE) return; // FIXME: Kludge. @@ -1164,10 +1164,10 @@ liberator.CommandLine = function () //{{{ .inputField.QueryInterface(Components.interfaces.nsIDOMNSEditableElement).editor; let sel = editor.selectionController.getSelection(SEL_TYPE); sel.removeAllRanges(); - if (liberator.completion.parenMatch != null) + if (completion.parenMatch != null) { let range = editor.selection.getRangeAt(0).cloneRange(); - let paren = liberator.completion.parenMatch + this.getCommand().indexOf(" ") + 1; + let paren = completion.parenMatch + this.getCommand().indexOf(" ") + 1; let node = range.startContainer; range.setStart(node, paren); range.setEnd(node, paren + 1); @@ -1194,7 +1194,7 @@ liberator.CommandLine = function () //{{{ completions = compl; completionList.selectItem(completionIndex); - if (liberator.options.get("wildoptions").has("auto")) + if (options.get("wildoptions").has("auto")) completionList.show(); var command = this.getCommand(); @@ -1223,7 +1223,7 @@ liberator.CommandLine = function () //{{{ * * TODO: get rid off "completion" variables, we are dealing with variables after all */ -liberator.ItemList = function (id) //{{{ +with (liberator) liberator.ItemList = function (id) //{{{ { //////////////////////////////////////////////////////////////////////////////// ////////////////////// PRIVATE SECTION ///////////////////////////////////////// @@ -1238,7 +1238,7 @@ liberator.ItemList = function (id) //{{{ var iframe = document.getElementById(id); if (!iframe) { - liberator.log("No iframe with id: " + id + " found, strange things may happen!"); // "The truth is out there..." -- djk + log("No iframe with id: " + id + " found, strange things may happen!"); // "The truth is out there..." -- djk return; } @@ -1267,11 +1267,11 @@ liberator.ItemList = function (id) //{{{ function createRow([b, c, a], dom) { /* Obviously, ItemList shouldn't know or care about this. */ - let filter = liberator.completion.filterString; + let filter = completion.filterString; if (filter) { - b = liberator.template.highlightFilter(b, filter); - c = liberator.template.highlightFilter(c, filter); + b = template.highlightFilter(b, filter); + c = template.highlightFilter(c, filter); } if (typeof a == "function") @@ -1285,7 +1285,7 @@ liberator.ItemList = function (id) //{{{ ; if (dom) - return liberator.util.xmlToDom(row, doc); + return util.xmlToDom(row, doc); return row; } @@ -1335,18 +1335,18 @@ liberator.ItemList = function (id) //{{{
; let tbody = div.div; - for (let i in liberator.util.range(offset, endIndex)) + for (let i in util.range(offset, endIndex)) tbody.* += createRow(completions[i]); div.* +=
{ - liberator.template.map(liberator.util.range(0, maxItems), function (i) + template.map(util.range(0, maxItems), function (i)
  • ~
) }
; - let dom = liberator.util.xmlToDom(div, doc); + let dom = util.xmlToDom(div, doc); completionBody = dom.getElementsByClassName("completion-items")[0]; completionElements = completionBody.childNodes; doc.body.replaceChild(dom, doc.body.firstChild); @@ -1432,7 +1432,7 @@ liberator.ItemList = function (id) //{{{ //}}} }; //}}} -liberator.StatusLine = function () //{{{ +with (liberator) liberator.StatusLine = function () //{{{ { //////////////////////////////////////////////////////////////////////////////// ////////////////////// PRIVATE SECTION ///////////////////////////////////////// @@ -1453,7 +1453,7 @@ liberator.StatusLine = function () //{{{ ////////////////////// OPTIONS ///////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ - liberator.options.add(["laststatus", "ls"], + options.add(["laststatus", "ls"], "Show the status line", "number", 2, { @@ -1462,7 +1462,7 @@ liberator.StatusLine = function () //{{{ if (value == 0) document.getElementById("status-bar").collapsed = true; else if (value == 1) - liberator.echo("show status line only with > 1 window not implemented yet"); + echo("show status line only with > 1 window not implemented yet"); else document.getElementById("status-bar").collapsed = false; @@ -1515,12 +1515,12 @@ liberator.StatusLine = function () //{{{ return; } - url = liberator.buffer.URL; + url = buffer.URL; // make it even more vim-like if (url == "about:blank") { - var title = liberator.buffer.title; + var title = buffer.title; if (!title) url = "[No Name]"; } @@ -1530,7 +1530,7 @@ liberator.StatusLine = function () //{{{ } // when session information is available, add [+] when we can go backwards - if (liberator.config.name == "Vimperator") + if (config.name == "Vimperator") { var sh = getWebNavigation().sessionHistory; var modified = ""; @@ -1538,7 +1538,7 @@ liberator.StatusLine = function () //{{{ modified += "+"; if (sh.index < sh.count -1) modified += "-"; - if (liberator.bookmarks.isBookmarked(liberator.buffer.URL)) + if (bookmarks.isBookmarked(buffer.URL)) modified += "\u2764"; // a heart symbol: ❤ //modified += "\u2665"; // a heart symbol: ♥ @@ -1593,14 +1593,13 @@ liberator.StatusLine = function () //{{{ return; } - let tabs = getBrowser().mTabs; - for (let i = 0; i < tabs.length; i++) - tabs[i].setAttribute("ordinal", i + 1); + for (let [i, tab] in Iterator(getBrowser().mTabs)) + tab.setAttribute("ordinal", i + 1); if (!currentIndex || typeof currentIndex != "number") - currentIndex = liberator.tabs.index() + 1; + currentIndex = tabs.index() + 1; if (!totalTabs || typeof currentIndex != "number") - totalTabs = liberator.tabs.count; + totalTabs = tabs.count; tabCountWidget.value = "[" + currentIndex + "/" + totalTabs + "]"; }, diff --git a/content/util.js b/content/util.js index a5b6ebe7..20ef3ad2 100644 --- a/content/util.js +++ b/content/util.js @@ -26,7 +26,7 @@ the provisions above, a recipient may use your version of this file under the terms of any one of the MPL, the GPL or the LGPL. }}} ***** END LICENSE BLOCK *****/ -liberator.util = { //{{{ +with (liberator) liberator.util = { //{{{ Timer: function Timer(minInterval, maxInterval, callback) { @@ -104,7 +104,7 @@ liberator.util = { //{{{ clipboardHelper.copyString(str); if (verbose) - liberator.echo("Yanked " + str, liberator.commandline.FORCE_SINGLELINE); + echo("Yanked " + str, commandline.FORCE_SINGLELINE); }, createURI: function (str) @@ -184,9 +184,9 @@ liberator.util = { //{{{ generateHelp: function (command, extraHelp) { var start = "", end = ""; - if (command instanceof liberator.Command) + if (command instanceof Command) start = ":"; - else if (command instanceof liberator.Option) + else if (command instanceof Option) start = end = "'"; var ret = ""; @@ -275,7 +275,7 @@ liberator.util = { //{{{ } catch (e) {} - value = liberator.template.highlight(value, true); + value = template.highlight(value, true); if (color) { value = value.toXMLString(); @@ -303,8 +303,8 @@ liberator.util = { //{{{ if (Date.now() > endTime) { liberator.interrupted = false; - liberator.threadYield(); - if (liberator.interrupted) + threadYield(); + if (interrupted) throw new Error("Interrupted"); endTime = Date.now() + time; } @@ -346,13 +346,13 @@ liberator.util = { //{{{ // and returns an array ['www.google.com/search?q=bla', 'www.osnews.com'] stringToURLArray: function (str) { - var urls = str.split(new RegExp("\s*" + liberator.options["urlseparator"] + "\s*")); + var urls = str.split(new RegExp("\s*" + options["urlseparator"] + "\s*")); for (let url = 0; url < urls.length; url++) { try { - var file = liberator.io.getFile(urls[url]); + var file = io.getFile(urls[url]); if (file.exists() && file.isReadable()) { urls[url] = file.path; @@ -376,7 +376,7 @@ liberator.util = { //{{{ // like the comments below ;-) // check for a search engine match in the string - var searchURL = liberator.bookmarks.getSearchURL(urls[url], false); + var searchURL = bookmarks.getSearchURL(urls[url], false); if (searchURL) { urls[url] = searchURL; @@ -384,7 +384,7 @@ liberator.util = { //{{{ } else // no search engine match, search for the whole string in the default engine { - searchURL = liberator.bookmarks.getSearchURL(urls[url], true); + searchURL = bookmarks.getSearchURL(urls[url], true); if (searchURL) { urls[url] = searchURL; @@ -464,6 +464,7 @@ liberator.util.Struct = function Struct() ConStructor.prototype = self; return self.constructor = ConStructor; } + liberator.util.Struct.prototype = { clone: function () { @@ -472,6 +473,7 @@ liberator.util.Struct.prototype = { // Iterator over our named members __iterator__: function () ([v, this[v]] for ([k, v] in this.members)) } + // Add no-sideeffect array methods. Can't set new Array() as the prototype or // get length() won't work. for (let [,k] in Iterator(["concat", "every", "filter", "forEach", "indexOf", "join", "lastIndexOf", diff --git a/content/vimperator.js b/content/vimperator.js index a399a2be..d545bcfe 100644 --- a/content/vimperator.js +++ b/content/vimperator.js @@ -26,7 +26,7 @@ the provisions above, a recipient may use your version of this file under the terms of any one of the MPL, the GPL or the LGPL. }}} ***** END LICENSE BLOCK *****/ -liberator.config = { //{{{ +with (liberator) liberator.config = { //{{{ /*** required options, no checks done if they really exist, so be careful ***/ name: "Vimperator", hostApplication: "Firefox", @@ -68,7 +68,7 @@ liberator.config = { //{{{ ["customizetoolbar", "Customize the Toolbar", function () { BrowserCustomizeToolbar(); }], ["dominspector", "DOM Inspector", - function () { try { inspectDOMDocument(content.document); } catch (e) { liberator.echoerr("DOM Inspector extension not installed"); } }], + function () { try { inspectDOMDocument(content.document); } catch (e) { echoerr("DOM Inspector extension not installed"); } }], ["downloads", "Manage Downloads", function () { toOpenWindowByType("Download:Manager", "chrome://mozapps/content/downloads/downloads.xul", "chrome,dialog=no,resizable"); }], ["history", "List your history", @@ -98,7 +98,7 @@ liberator.config = { //{{{ ["searchengines", "Manage installed search engines", function () { openDialog("chrome://browser/content/search/engineManager.xul", "_blank", "chrome,dialog,modal,centerscreen"); }], ["selectionsource", "View selection source", - function () { liberator.buffer.viewSelectionSource(); }] + function () { buffer.viewSelectionSource(); }] ], // they are sorted by relevance, not alphabetically @@ -114,12 +114,12 @@ liberator.config = { //{{{ { function incrementURL(count) { - var url = liberator.buffer.URL; + var url = buffer.URL; var regex = /(.*?)(\d+)(\D*)$/; var matches = url.match(regex); if (!matches || !matches[2]) // no number to increment - return liberator.beep(); + return beep(); var newNum = parseInt(matches[2], 10) + count + ""; // "" to make sure its a string var nums = newNum.match(/^(-?)(\d+)$/); @@ -129,71 +129,71 @@ liberator.config = { //{{{ newNum += "0"; // keep leading zeros newNum += nums[2]; - liberator.open(matches[1] + newNum + matches[3]); + open(matches[1] + newNum + matches[3]); } // load Vimperator specific modules - liberator.loadModule("search", liberator.Search); - liberator.loadModule("bookmarks", liberator.Bookmarks); - liberator.loadModule("history", liberator.History); - liberator.loadModule("tabs", liberator.Tabs); - liberator.loadModule("marks", liberator.Marks); - liberator.loadModule("quickmarks", liberator.QuickMarks); - liberator.loadModule("hints", liberator.Hints); + loadModule("search", Search); + loadModule("bookmarks", Bookmarks); + loadModule("history", History); + loadModule("tabs", Tabs); + loadModule("marks", Marks); + loadModule("quickmarks", QuickMarks); + loadModule("hints", Hints); //////////////////////////////////////////////////////////////////////////////// ////////////////////// MAPPINGS //////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ - liberator.mappings.add([liberator.modes.NORMAL], + mappings.add([modes.NORMAL], ["y"], "Yank current location to the clipboard", - function () { liberator.util.copyToClipboard(liberator.buffer.URL, true); }); + function () { util.copyToClipboard(buffer.URL, true); }); // opening websites - liberator.mappings.add([liberator.modes.NORMAL], + mappings.add([modes.NORMAL], ["o"], "Open one or more URLs", - function () { liberator.commandline.open(":", "open ", liberator.modes.EX); }); + function () { commandline.open(":", "open ", modes.EX); }); - liberator.mappings.add([liberator.modes.NORMAL], ["O"], + mappings.add([modes.NORMAL], ["O"], "Open one or more URLs, based on current location", - function () { liberator.commandline.open(":", "open " + liberator.buffer.URL, liberator.modes.EX); }); + function () { commandline.open(":", "open " + buffer.URL, modes.EX); }); - liberator.mappings.add([liberator.modes.NORMAL], ["t"], + mappings.add([modes.NORMAL], ["t"], "Open one or more URLs in a new tab", - function () { liberator.commandline.open(":", "tabopen ", liberator.modes.EX); }); + function () { commandline.open(":", "tabopen ", modes.EX); }); - liberator.mappings.add([liberator.modes.NORMAL], ["T"], + mappings.add([modes.NORMAL], ["T"], "Open one or more URLs in a new tab, based on current location", - function () { liberator.commandline.open(":", "tabopen " + liberator.buffer.URL, liberator.modes.EX); }); + function () { commandline.open(":", "tabopen " + buffer.URL, modes.EX); }); - liberator.mappings.add([liberator.modes.NORMAL], + mappings.add([modes.NORMAL], [""], "Increment last number in URL", function (count) { incrementURL(count > 1 ? count : 1); }, - { flags: liberator.Mappings.flags.COUNT }); + { flags: Mappings.flags.COUNT }); - liberator.mappings.add([liberator.modes.NORMAL], + mappings.add([modes.NORMAL], [""], "Decrement last number in URL", function (count) { incrementURL(-(count > 1 ? count : 1)); }, - { flags: liberator.Mappings.flags.COUNT }); + { flags: Mappings.flags.COUNT }); - liberator.mappings.add([liberator.modes.NORMAL], ["~"], + mappings.add([modes.NORMAL], ["~"], "Open home directory", - function () { liberator.open("~"); }); + function () { open("~"); }); - liberator.mappings.add([liberator.modes.NORMAL], ["gh"], + mappings.add([modes.NORMAL], ["gh"], "Open homepage", function () { BrowserHome(); }); - liberator.mappings.add([liberator.modes.NORMAL], ["gH"], + mappings.add([modes.NORMAL], ["gH"], "Open homepage in a new tab", function () { var homepages = gHomeButton.getHomePage(); - liberator.open(homepages, /\bhomepage\b/.test(liberator.options["activate"]) ? - liberator.NEW_TAB : liberator.NEW_BACKGROUND_TAB); + open(homepages, /\bhomepage\b/.test(options["activate"]) ? + NEW_TAB : NEW_BACKGROUND_TAB); }); - liberator.mappings.add([liberator.modes.NORMAL], ["gu"], + mappings.add([modes.NORMAL], ["gu"], "Go to parent directory", function (count) { @@ -202,7 +202,7 @@ liberator.config = { //{{{ if (/^file:\/|^\//.test(url)) { //var strippedFilename = url.replace(/^(file:\/\/)?(.*)/, "$2"); - var file = liberator.io.getFile(url); + var file = io.getFile(url); if (!file.exists() || !file.isDirectory()) return false; else @@ -216,7 +216,7 @@ liberator.config = { //{{{ if (count < 1) count = 1; - var url = liberator.buffer.URL; + var url = buffer.URL; for (let i = 0; i < count; i++) { if (isDirectory(url)) @@ -226,53 +226,53 @@ liberator.config = { //{{{ } url = url.replace(/^(.*:\/+.*?)\/+$/, "$1/"); // get rid of more than 1 / at the end - if (url == liberator.buffer.URL) + if (url == buffer.URL) { - liberator.beep(); + beep(); return; } - liberator.open(url); + open(url); }, - { flags: liberator.Mappings.flags.COUNT }); + { flags: Mappings.flags.COUNT }); - liberator.mappings.add([liberator.modes.NORMAL], ["gU"], + mappings.add([modes.NORMAL], ["gU"], "Go to the root of the website", function () { var uri = content.document.location; if (/(about|mailto):/.test(uri.protocol)) // exclude these special protocols for now { - liberator.beep(); + beep(); return; } - liberator.open(uri.protocol + "//" + (uri.host || "") + "/"); + open(uri.protocol + "//" + (uri.host || "") + "/"); }); - liberator.mappings.add([liberator.modes.NORMAL], [""], + mappings.add([modes.NORMAL], [""], "Redraw the screen", - function () { liberator.commands.get("redraw").execute(); }); + function () { commands.get("redraw").execute(); }); /////////////////////////////////////////////////////////////////////////////}}} ////////////////////// COMMANDS //////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ - liberator.commands.add(["downl[oads]", "dl"], + commands.add(["downl[oads]", "dl"], "Show progress of current downloads", function () { - liberator.open("chrome://mozapps/content/downloads/downloads.xul", - liberator.options.get("newtab").has("all", "downloads") - ? liberator.NEW_TAB : liberator.CURRENT_TAB); + open("chrome://mozapps/content/downloads/downloads.xul", + options.get("newtab").has("all", "downloads") + ? NEW_TAB : CURRENT_TAB); }, { argCount: "0" }); - liberator.commands.add(["o[pen]", "e[dit]"], + commands.add(["o[pen]", "e[dit]"], "Open one or more URLs in the current tab", function (args, special) { if (args) { - liberator.open(args); + open(args); } else { @@ -284,10 +284,10 @@ liberator.config = { //{{{ }, { bang: true, - completer: function (filter) liberator.completion.url(filter) + completer: function (filter) completion.url(filter) }); - liberator.commands.add(["redr[aw]"], + commands.add(["redr[aw]"], "Redraw the screen", function () { @@ -298,7 +298,7 @@ liberator.config = { //{{{ { argCount: "0" }); // TODO: move sidebar commands to ui.js? - liberator.commands.add(["sbcl[ose]"], + commands.add(["sbcl[ose]"], "Close the sidebar window", function () { @@ -307,7 +307,7 @@ liberator.config = { //{{{ }, { argCount: "0" }); - liberator.commands.add(["sideb[ar]", "sb[ar]", "sbope[n]"], + commands.add(["sideb[ar]", "sb[ar]", "sbope[n]"], "Open the sidebar window", function (args) { @@ -327,34 +327,34 @@ liberator.config = { //{{{ return; } } - liberator.echoerr("No sidebar " + args.string + " found"); + echoerr("No sidebar " + args.string + " found"); }, { argCount: "+", - completer: function (filter) liberator.completion.sidebar(filter) + completer: function (filter) completion.sidebar(filter) }); - liberator.commands.add(["winc[lose]", "wc[lose]"], + commands.add(["winc[lose]", "wc[lose]"], "Close window", function () { window.close(); }, { argCount: "0" }); - liberator.commands.add(["wino[pen]", "wo[pen]", "wine[dit]"], + commands.add(["wino[pen]", "wo[pen]", "wine[dit]"], "Open one or more URLs in a new window", function (args) { if (args) - liberator.open(args, liberator.NEW_WINDOW); + open(args, NEW_WINDOW); else - liberator.open("about:blank", liberator.NEW_WINDOW); + open("about:blank", NEW_WINDOW); }, - { completer: function (filter) liberator.completion.url(filter) }); + { completer: function (filter) completion.url(filter) }); /////////////////////////////////////////////////////////////////////////////}}} ////////////////////// OPTIONS ///////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ - liberator.options.add(["online"], + options.add(["online"], "Set the 'work offline' option", "boolean", true, { @@ -375,7 +375,7 @@ liberator.config = { //{{{ } }); - liberator.options.add(["titlestring"], + options.add(["titlestring"], "Change the title of the window", "string", "Vimperator", { @@ -383,7 +383,7 @@ liberator.config = { //{{{ { try { - var id = liberator.config.mainWindowID || "main-window"; + var id = config.mainWindowID || "main-window"; document.getElementById(id).setAttribute("titlemodifier", value); if (window.content.document.title.length > 0) document.title = window.content.document.title + " - " + value; @@ -392,14 +392,14 @@ liberator.config = { //{{{ } catch (e) { - liberator.log("Couldn't set titlestring", 3); + log("Couldn't set titlestring", 3); } return value; } }); - liberator.options.add(["urlseparator"], + options.add(["urlseparator"], "Set the separator regexp used to separate multiple URL args", "string", ",\\s"); }