Skip to content

Commit

Permalink
Make dfn.js work for headings
Browse files Browse the repository at this point in the history
Fixes #26.
  • Loading branch information
annevk authored and zcorpan committed Nov 22, 2016
1 parent 86c6b95 commit 7222360
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
12 changes: 4 additions & 8 deletions dfn.js
Expand Up @@ -2,8 +2,6 @@
// makes <dfn> elements link back to all uses of the term
// no copyright is asserted on this file

var dfnTimer = new Date();

var dfnMapTarget = -1;
var dfnMapDone = false;
var dfnMap = {};
Expand All @@ -19,7 +17,7 @@ function initDfn() {
var start = new Date();
while (k < dfnMapTarget) {
if (links[k].hash.length > 1) {
if (!links[k].closest('.no-backref, .self-link, ul.index, #idl-index + pre')) {
if (!links[k].closest('.no-backref, .self-link, ul.index, #idl-index + pre, ol.toc')) {
var s;
if (links[k].hasAttribute('data-x-internal'))
s = links[k].getAttribute('data-x-internal')
Expand All @@ -45,8 +43,6 @@ function initDfn() {
}
dfnMapDone = true;
document.body.className += " dfnEnabled";
//if (getCookie('profile') == '1')
// document.getElementsByTagName('h2')[0].textContent += '; dfn.js: ' + (new Date() - dfnTimer) + 'ms to do ' + dfnMapTarget + ' links in ' + n + ' loops';
}
initDfnInternal();
}
Expand All @@ -66,7 +62,7 @@ function dfnShow(event) {
}
if (dfnMapDone) {
var node = event.target;
while (node && (node.nodeType != event.target.ELEMENT_NODE || node.tagName != "DFN"))
while (node && (!node instanceof HTMLElement || !(node.localName == 'dfn' || (node instanceof HTMLHeadingElement && node.hasAttribute('data-dfn-type')))))
node = node.parentNode;
if (node) {
event.preventDefault();
Expand Down Expand Up @@ -175,9 +171,9 @@ function dfnMovePanel(event) {
function dfnGetCaption(link) {
var node = link;
while (node) {
if (node.nodeType == node.ELEMENT_NODE && node.tagName.match(/^H[1-6]$/)) {
if (node instanceof HTMLHeadingElement) {
return node;
} else if (node.nodeType == node.ELEMENT_NODE && node.tagName == 'NAV') {
} else if (node instanceof HTMLElement && node.localName == 'nav') {
return 'Navigation';
} else if (!node.previousSibling) {
node = node.parentNode;
Expand Down
2 changes: 1 addition & 1 deletion standard.css
Expand Up @@ -289,7 +289,7 @@ html:not(.split) #multipage-link { animation: 10s ease 0s 1 stand-out; }
p.copyright { text-align: center; }
p.copyright > span { display: inline-block; border: none; }

body.dfnEnabled dfn { cursor: pointer; }
body.dfnEnabled dfn, body.dfnEnabled h2[data-dfn-type], body.dfnEnabled h3[data-dfn-type], body.dfnEnabled h4[data-dfn-type], body.dfnEnabled h5[data-dfn-type], body.dfnEnabled h6[data-dfn-type] { cursor: pointer; }
.dfnPanel {
display: inline;
position: absolute;
Expand Down

0 comments on commit 7222360

Please sign in to comment.