/***** BEGIN LICENSE BLOCK ***** {{{ Version: MPL 1.1/GPL 2.0/LGPL 2.1 The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/ Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. (c) 2006-2007: Martin Stubenschrott Alternatively, the contents of this file may be used under the terms of either the GNU General Public License Version 2 or later (the "GPL"), or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), in which case the provisions of the GPL or the LGPL are applicable instead of those above. If you wish to allow use of your version of this file only under the terms of either the GPL or the LGPL, and not to allow others to use your version of this file under the terms of the MPL, indicate your decision by deleting the provisions above and replace them with the notice and other provisions required by the GPL or the LGPL. If you do not delete 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 *****/ vimperator.help = function(section, easter) //{{{ { if (easter) { vimperator.echoerr("E478: Don't panic!"); return; } if ((arguments[3] && arguments[3].inTab))// || !window.content.document.open) vimperator.open("about:blank", vimperator.NEW_TAB); else vimperator.open("about:blank"); /* commands = array where help information is located * beg = string which is printed before the commmand/option/mapping name * end = string which is printed after the commmand/option/mapping name * func = called with 'command', result is a string is prepended to the help text */ function makeHelpString(commands, beg, end, func) { var ret = ""; var separator = '
\n'; for (var command in commands) { // the usage information for the command ret += ''; for (var j=0; j < command.usage.length; j++) { var usage = command.usage[j]; // keep
//usage = usage.replace(/<([^b][^r].*>)/g, "<$1"); //usage = usage.replace(/[^b][^r][^\/]>/g, ">"); usage = usage.replace(//g, ">"); usage = usage.replace(/\\n/g, "
"); // color [count], [!], {arg} and [arg] in the usage, not nice and error prone but the regexp work (for now) usage = usage.replace(/({[^}]+})/g, "$1"); // required args usage = usage.replace(/(^|[^A-Za-z])(\[[^!\]]+\])/g, "$1$2"); // optional args usage = usage.replace(/\[!\]/, "[!]"); // special // and the 'option' in a different color usage = usage.replace(/^'(\w+)'/gm, "'$1'"); ret += "" + beg + usage + end + '
'; } ret += ''; // the actual help text with the first line in bold if (command.short_help) { ret += ''; ret += command.short_help; // the help description ret += "
"; if (func) // for options we print default values here, e.g. { ret += func.call(this, command); ret += "
"; } if (command.help) { ret += command.help; // the help description ret += "
"; } } else ret += "Sorry, no help available"; // the tags which are printed on the top right ret += ''; var names = command.names; for (var j=0; j < names.length; j++) { var cmd_name = names[j]; cmd_name = cmd_name.replace(//g, ">"); // cmd_name = cmd_name.replace(/"/g, """); // cmd_name = cmd_name.replace(/'/g, "'"); // cmd_name = cmd_name.replace(/&/g, "&"); ret += '' + beg + cmd_name + end + '
'; } ret += ''; // add more space between entries ret += separator; } ret = ret.replace(new RegExp(separator + '$'), ''); // FIXME: far too tasty! return ret; } function makeOptionsHelpString(command) { var ret = ""; ret = command.type + ' (default: '; if (command.type == "boolean") { if (command.default_value == true) ret += "on"; else ret += "off"; } else { if (typeof command.default_value == 'string' && command.default_value.length == 0) ret += "''"; else ret += command.default_value; } ret += ")
"; return ret; } var header = '

Vimperator

\n' + '

First there was a Navigator, then there was an Explorer.\n' + 'Later it was time for a Konqueror. Now it\'s time for an Imperator, the VIMperator :)

\n'; var introduction = 'introduction

Introduction

' + '

Vimperator is a free browser add-on for Firefox, which makes it look and behave like the Vim text editor. ' + 'It has similar key bindings, and you could call it a modal web browser, as key bindings differ according to which mode you are in.

\n' + '

Warning: To provide the most authentic Vim experience, the Firefox menubar and toolbar were hidden.
' + 'If you really need them, type: :set guioptions=mT to get it back.\n' + 'If you don\'t like Vimperator at all, you can uninstall it by typing :addons and remove/disable it. ' + 'If you like it, but can\'t remember the shortcuts, press F1 or :help to get this help window back.

\n' + '

Since Vimperator\'s GUI is embedded into a toolbar, it may look too 3D-like with the default theme. ' + 'For the best experience, I therefore recommend the Whitehart theme or any other flat theme.

\n' + '

Vimperator was written by Martin Stubenschrott. ' + 'If you appreciate my work on Vimperator and want to encourage me working on it more, you can either send me greetings, patches or make a donation:

\n' + '
\n
' + '' + '' + '' + '' + '
\n
\n' + '

Of course as a believer in free open source software, only make a donation if you really like Vimperator and the money doesn\'t hurt - otherwise just use it, recommend it and like it :)

\n' var mappings = 'mappings

Mappings

\n' + '

The denotion of modifier keys is like in Vim, so C- means the Control key, M- the Meta key, A- the Alt key and S- the Shift key.

'+ '' mappings += makeHelpString(vimperator.mappings, "", "", null); mappings += '
'; if (section && section == 'holy-grail') mappings += 'You found it, Arthur!\n'; var commands = 'commands

Commands

\n' + '\n'; commands += makeHelpString(vimperator.commands, ":", "", null); commands += '
'; if (section && section == '42') commands += '

What is the meaning of life, the universe and everything?
' + 'Douglas Adams, the only person who knew what this question really was about is
' + 'now dead, unfortunately. So now you might wonder what the meaning of death
' + 'is...

\n'; var options = 'options

Options

\n' + '\n'; options += makeHelpString(vimperator.options, "'", "'", makeOptionsHelpString); options += '
'; var fulldoc = '\n' + '\n' + '\n\nVimperator help\n' + // XXX: stylesheet broken here? Have to add it in the vimperator.xul file '\n' + '\n\n
\n' + 'version ' + vimperator.version + '\n' + header + introduction + mappings + commands + options + '\n
\n\n'; var doc = window.content.document; try { doc.open(); } catch(e) { // when the url is "about:" or any other xhtml page the doc is not open // then retry again in 250ms but just once if (arguments[3] && arguments[3].recursive) return false; vimperator.open("about:blank"); setTimeout(function () { vimperator.help(section, false, null, {recursive: true}); }, 250); return; } doc.write(fulldoc); doc.close(); // TODO: change to getBoundingClientRect() for FF 3.0 function cumulativeOffset(element) { var valueT = 0, valueL = 0; if (!element) return [0, 0]; do { valueT += element.offsetTop || 0; valueL += element.offsetLeft || 0; element = element.offsetParent; } while (element); return [valueL, valueT]; } if (section) { function findSectionElement(section) { return vimperator.buffer.evaluateXPath('//code[@class="tag" and text()="' + section + '"]') .snapshotItem(0); } var element = findSectionElement(section); if (!element) { var firstChar = section.charAt(0); if (firstChar != ':' && firstChar != "'") { element = findSectionElement(':' + section); if (!element) element = findSectionElement("'" + section + "'"); } } if (!element) { vimperator.echoerr("E149: Sorry, no help for " + section); return; } // FIXME: H2 elements are currently wrapped in DIVs so this works var pos = cumulativeOffset(element.parentNode); // horizontal offset is annoying, set it to 0 (use pos[0] if you want horizontal offset) window.content.scrollTo(0, pos[1]); } } //}}} // vim: set fdm=marker sw=4 ts=4 et: