1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-20 09:27:58 +01:00

Fix some generally silly, stupid, and/or annoying help quirks.

This commit is contained in:
Kris Maglione
2008-12-20 23:48:56 -05:00
parent 2f0132cabc
commit df7c7c9d51
4 changed files with 59 additions and 41 deletions

View File

@@ -1,8 +1,11 @@
const liberator = Components.classes["@mozilla.org/embedcomp/window-watcher;1"] const win = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
.getService(Components.interfaces.nsIWindowWatcher) .getService(Components.interfaces.nsIWindowWatcher)
.activeWindow .activeWindow;
.liberator; const liberator = win.liberator;
liberator.help(decodeURIComponent(document.location.search.substr(1))); let page = liberator.findHelp(decodeURIComponent(document.location.search.substr(1)));
let url = "chrome://liberator/locale/" + page;
win.getBrowser().loadURIWithFlags(url, Components.interfaces.nsIWebNavigation.LOAD_FLAGS_REPLACE_HISTORY, null, null, null);

View File

@@ -939,6 +939,28 @@ const liberator = (function () //{{{
return extensions.some(function (e) e.name == name); return extensions.some(function (e) e.name == name);
}, },
findHelp: function (topic)
{
let items = completion.runCompleter("help", topic);
let partialMatch = null;
function format(item) item[1] + "#" + encodeURIComponent(item[0]);
for (let [i, item] in Iterator(items))
{
if (item[0] == topic)
return format(item);
else if (partialMatch == -1 && item[0].indexOf(topic) > -1)
{
partialMatch = item;
}
}
if (partialMatch)
return format(partialMatch);
return null;
},
help: function (topic) help: function (topic)
{ {
let where = (options["newtab"] && options.get("newtab").has("all", "help")) let where = (options["newtab"] && options.get("newtab").has("all", "help"))
@@ -952,43 +974,16 @@ const liberator = (function () //{{{
liberator.open("chrome://liberator/locale/" + helpFile, where); liberator.open("chrome://liberator/locale/" + helpFile, where);
else else
liberator.echomsg("Sorry, help file " + helpFile.quote() + " not found"); liberator.echomsg("Sorry, help file " + helpFile.quote() + " not found");
return; return;
} }
function jumpToTag(file, tag) let page = this.findHelp(topic);
{ if (page == null)
liberator.open("chrome://liberator/locale/" + file, where); return liberator.echoerr("E149: Sorry, no help for " + topic);
// TODO: it would be better to wait for pageLoad
setTimeout(function () {
let elem = buffer.evaluateXPath('//*[@class="tag" and text()="' + tag + '"]').snapshotItem(0);
if (elem)
window.content.scrollTo(0, elem.getBoundingClientRect().top - 10); // 10px context
else
liberator.dump('no element: ' + '@class="tag" and text()="' + tag + '"\n' );
}, 500);
}
let items = completion.runCompleter("help", topic); liberator.open("chrome://liberator/locale/" + page, where);
let partialMatch = -1; if (where == this.CURRENT_TAB)
content.postMessage("fragmentChange", "*");
for (let [i, item] in Iterator(items))
{
if (item[0] == topic)
{
jumpToTag(item[1], item[0]);
return;
}
else if (partialMatch == -1 && item[0].indexOf(topic) > -1)
{
partialMatch = i;
}
}
if (partialMatch > -1)
jumpToTag(items[partialMatch][1], items[partialMatch][0]);
else
liberator.echoerr("E149: Sorry, no help for " + topic);
}, },
globalVariables: {}, globalVariables: {},

View File

@@ -76,8 +76,8 @@ tag=<span class="tag">|</span>
key=<div class="key">|</div> key=<div class="key">|</div>
option=<a class="option" href="#">|</a> option=<a class="option" href="#">|</a>
option2=<a class="option" href="#">'|'</a> option2=<a class="option" href="#">'|'</a>
command=<a class="command">|</a> command=<a class="command" href="#">|</a>
mapping=<a class="mapping">|</a> mapping=<a class="mapping" href="#">|</a>
argument=<span class="argument">|</span> argument=<span class="argument">|</span>
argument2=<span class="argument">&#123;|&#125;</span> argument2=<span class="argument">&#123;|&#125;</span>
argument3=<span class="argument">[|]</span> argument3=<span class="argument">[|]</span>

View File

@@ -1,7 +1,27 @@
function checkFragment()
{
let frag = document.location.hash.substr(1);
if (!frag || document.getElementById(frag))
return;
let elem = document.evaluate('//*[@class="tag" and text()="' + frag + '"]', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotItem(0);
if (elem)
window.content.scrollTo(0, elem.getBoundingClientRect().top - 10); // 10px context
}
document.addEventListener("load", checkFragment, true);
window.addEventListener("message", function (event) {
if (event.data == "fragmentChange")
checkFragment();
}, true);
document.addEventListener("click", function (event) { document.addEventListener("click", function (event) {
let elem = event.target; let elem = event.target;
if (/^(option|mapping|command)$/.test(elem.className)) if (/^(option|mapping|command)$/.test(elem.className))
elem.setAttribute("href", "chrome://liberator/content/help.xul?" + encodeURIComponent(elem.textContent.replace(/\s.*/, ""))); var tag = elem.textContent.replace(/\s.*/, "");
if (elem.className == "command")
tag = tag.replace(/\[.*?\]/g, "");
if (tag)
elem.href = "chrome://liberator/content/help.xul?" + encodeURIComponent(tag);
}, true); }, true);