mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-20 11:18:00 +01:00
Fix some generally silly, stupid, and/or annoying help quirks.
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
|
||||
const liberator = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
|
||||
.getService(Components.interfaces.nsIWindowWatcher)
|
||||
.activeWindow
|
||||
.liberator;
|
||||
const win = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
|
||||
.getService(Components.interfaces.nsIWindowWatcher)
|
||||
.activeWindow;
|
||||
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);
|
||||
|
||||
|
||||
@@ -939,6 +939,28 @@ const liberator = (function () //{{{
|
||||
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)
|
||||
{
|
||||
let where = (options["newtab"] && options.get("newtab").has("all", "help"))
|
||||
@@ -952,43 +974,16 @@ const liberator = (function () //{{{
|
||||
liberator.open("chrome://liberator/locale/" + helpFile, where);
|
||||
else
|
||||
liberator.echomsg("Sorry, help file " + helpFile.quote() + " not found");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
function jumpToTag(file, tag)
|
||||
{
|
||||
liberator.open("chrome://liberator/locale/" + file, where);
|
||||
// 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 page = this.findHelp(topic);
|
||||
if (page == null)
|
||||
return liberator.echoerr("E149: Sorry, no help for " + topic);
|
||||
|
||||
let items = completion.runCompleter("help", topic);
|
||||
let partialMatch = -1;
|
||||
|
||||
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);
|
||||
liberator.open("chrome://liberator/locale/" + page, where);
|
||||
if (where == this.CURRENT_TAB)
|
||||
content.postMessage("fragmentChange", "*");
|
||||
},
|
||||
|
||||
globalVariables: {},
|
||||
|
||||
@@ -76,8 +76,8 @@ tag=<span class="tag">|</span>
|
||||
key=<div class="key">|</div>
|
||||
option=<a class="option" href="#">|</a>
|
||||
option2=<a class="option" href="#">'|'</a>
|
||||
command=<a class="command">|</a>
|
||||
mapping=<a class="mapping">|</a>
|
||||
command=<a class="command" href="#">|</a>
|
||||
mapping=<a class="mapping" href="#">|</a>
|
||||
argument=<span class="argument">|</span>
|
||||
argument2=<span class="argument">{|}</span>
|
||||
argument3=<span class="argument">[|]</span>
|
||||
|
||||
@@ -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) {
|
||||
let elem = event.target;
|
||||
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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user