Skip to content

Commit

Permalink
JS: Move addAnchorLinks from main.js to base.js
Browse files Browse the repository at this point in the history
Thanks Saïvann!
  • Loading branch information
harding committed Apr 25, 2015
1 parent feea5bb commit 6264930
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
17 changes: 17 additions & 0 deletions js/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,20 @@ setTimeout(function() {
}
}, 1);
}

function addAnchorLinks() {
// Apply anchor links icon on each title displayed on CSS hover.
var nodes = [];
var tags = ['H2', 'H3', 'H4', 'H5', 'H6'];
for (var i = 0, n = tags.length; i < n; i++) {
for (var ii = 0, t = document.getElementsByTagName(tags[i]), nn = t.length; ii < nn; ii++) nodes.push(t[ii]);
}
for (var i = 0, n = nodes.length; i < n; i++) {
if (!nodes[i].id) continue;
if (nodes[i].getElementsByTagName('A').length > 0 && nodes[i].getElementsByTagName('A')[0].innerHTML == '') return;
addClass(nodes[i], 'anchorAf');
var anc = document.createElement('A');
anc.href = '#' + nodes[i].id;
nodes[i].insertBefore(anc, nodes[i].firstChild);
}
}
17 changes: 0 additions & 17 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,23 +297,6 @@ addEvent(window, 'load', evtimestamp);
init();
}

function addAnchorLinks() {
// Apply anchor links icon on each title displayed on CSS hover.
var nodes = [];
var tags = ['H2', 'H3', 'H4', 'H5', 'H6'];
for (var i = 0, n = tags.length; i < n; i++) {
for (var ii = 0, t = document.getElementsByTagName(tags[i]), nn = t.length; ii < nn; ii++) nodes.push(t[ii]);
}
for (var i = 0, n = nodes.length; i < n; i++) {
if (!nodes[i].id) continue;
if (nodes[i].getElementsByTagName('A').length > 0 && nodes[i].getElementsByTagName('A')[0].innerHTML == '') return;
addClass(nodes[i], 'anchorAf');
var anc = document.createElement('A');
anc.href = '#' + nodes[i].id;
nodes[i].insertBefore(anc, nodes[i].firstChild);
}
}

function updateIssue(e) {
// Update GitHub issue link pre-filled with current page location.
var t = getEventTarget(e);
Expand Down

0 comments on commit 6264930

Please sign in to comment.