diff --git a/common/content/help.js b/common/content/help.js index b25ecf51..3ae6d96e 100644 --- a/common/content/help.js +++ b/common/content/help.js @@ -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); diff --git a/common/content/liberator.js b/common/content/liberator.js index eb9d6574..35a71efb 100644 --- a/common/content/liberator.js +++ b/common/content/liberator.js @@ -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: {}, diff --git a/vimperator/locale/en-US/asciidoc.conf b/vimperator/locale/en-US/asciidoc.conf index 41366f40..0a76bab0 100644 --- a/vimperator/locale/en-US/asciidoc.conf +++ b/vimperator/locale/en-US/asciidoc.conf @@ -76,8 +76,8 @@ tag=| key=
|
option=| option2='|' -command=| -mapping=| +command=| +mapping=| argument=| argument2={|} argument3=[|] diff --git a/vimperator/locale/en-US/help.js b/vimperator/locale/en-US/help.js index 17a20a4e..00889f12 100644 --- a/vimperator/locale/en-US/help.js +++ b/vimperator/locale/en-US/help.js @@ -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);