mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-21 21:47:59 +01:00
233 lines
13 KiB
JavaScript
233 lines
13 KiB
JavaScript
/***** 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 <stubenschrott@gmx.net>
|
||
|
||
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 *****/
|
||
|
||
function help(section, easter)
|
||
{
|
||
if (easter)
|
||
{
|
||
echoerr("E478: Don't panic!");
|
||
return;
|
||
}
|
||
if ((arguments[3] && arguments[3].inTab) || !window.content.document.open)
|
||
openURLsInNewTab("", true);
|
||
|
||
var doc = window.content.document;
|
||
|
||
// xxx: for firebug: :js Firebug.toggleBar(true)
|
||
|
||
/* commands = array where help information is located
|
||
* color = used for background of the table
|
||
* beg = string which is printed before the commmand/setting/mapping name
|
||
* end = string which is printed after the commmand/setting/mapping name
|
||
* func = called with 'command', result is a string is prepended to the help text
|
||
*/
|
||
function makeHelpString(commands, color, beg, end, func)
|
||
{
|
||
var ret = "";
|
||
for (var i=0; i < commands.length; i++)
|
||
{
|
||
// the usage information for the command
|
||
ret += '</td></tr><tr class="description"><td class="usage" valign="top">';
|
||
for (var j=0; j < commands[i][USAGE].length; j++)
|
||
{
|
||
var usage = commands[i][USAGE][j];
|
||
|
||
// keep <br/>
|
||
//usage = usage.replace(/<([^b][^r].*>)/g, "<$1");
|
||
//usage = usage.replace(/[^b][^r][^\/]>/g, ">");
|
||
usage = usage.replace(/</g, "<");
|
||
usage = usage.replace(/>/g, ">");
|
||
usage = usage.replace(/\\n/g, "<br/>");
|
||
// color {count} and [url] arguments in the usage, not nice and error prone but the regexp work (for now)
|
||
usage = usage.replace(/(^|;|\n|\s|\]|\}|=|<br\/?>)({.*?}|\[.*?\])/gm, "$1<span class=argument>$2</span>");
|
||
// and the 'setting' in a different color
|
||
usage = usage.replace(/^'(\w+)'/gm, "'<span class=setting>$1</span>'");
|
||
ret += "<code>" +beg+ usage +end+ '</code><br/>';
|
||
}
|
||
ret += '</td><td valign="top">';
|
||
|
||
// the actual help text with the first line in bold
|
||
if (commands[i][SHORTHELP])
|
||
{
|
||
ret += "<b>";
|
||
ret += commands[i][SHORTHELP]; // the help description
|
||
ret += "</b><br/>";
|
||
if(func) // for settings whe print default values here, e.g.
|
||
{
|
||
ret += func.call(this, commands[i]);
|
||
ret += "<br/>";
|
||
}
|
||
if (commands[i][HELP])
|
||
{
|
||
ret += commands[i][HELP]; // the help description
|
||
ret += "<br/>";
|
||
}
|
||
}
|
||
else
|
||
ret += "Sorry, no help available";
|
||
// the tags which are printed on the top right
|
||
//ret += '<tr class="tag"><td colspan="1">====================================';
|
||
ret += '<td class="tag" valign="top">';
|
||
for (var j=0; j < commands[i][COMMANDS].length; j++)
|
||
{
|
||
var cmd_name = commands[i][COMMANDS][j];
|
||
cmd_name = cmd_name.replace(/</g, "<");
|
||
cmd_name = cmd_name.replace(/>/g, ">");
|
||
ret += '<code id="' +beg+ commands[i][COMMANDS][j] +end+ '">' +beg+ cmd_name +end+ '</code><br/>';
|
||
}
|
||
ret += '</td></tr>';
|
||
|
||
// add more space between entries
|
||
if (i < commands.length-1)
|
||
ret += '<tr class="separator"><td colspan=3><hr></td></tr> |