Translations of this page?:

Copy Section Link

An easy way to copy each section link. Copy these files into your conf directory. (Or if they already exist, copy the code into them.)

(As requested on http://forum.dokuwiki.org/thread/5709.)

./conf/userscript.js
/** Show each section link when hovering over each respective headline.
  *
  * @author Anika Henke <anika@selfthinker.org>
  * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
  */
function addWikiLinksToHeadlines() {
    // iterate through all headlines
    for (var i=1; i<6; i++) {
        for (var j=0; j<document.getElementsByTagName("h"+i).length; j++) {
            // ".firstChild" should be removed for the next DokuWiki version
            var elem = document.getElementsByTagName("h"+i)[j].firstChild;
            if (elem!=null && elem.firstChild!=null) {
                // build wiki link
                var ID        = elem.id;
                var text      = elem.firstChild.data;
                var wikiLink  = '[[:'+JSINFO.id+'#'+ID+'|'+text+']]';
                // add wiki link to headline
                var container = document.createElement('span');
                container.setAttribute("class", "wikiLink");
                container.innerHTML = wikiLink;
                elem.appendChild(container);
            }
        }
    }
}
 
addInitEvent(addWikiLinksToHeadlines);
./conf/userstyle.css
.dokuwiki .page h1,
.dokuwiki .page h2,
.dokuwiki .page h3,
.dokuwiki .page h4,
.dokuwiki .page h5 {
    position: relative;
}
 
.dokuwiki a span.wikiLink {
    display: none;
    color: #999;
    background-color: #fff;
    font: normal 11px Arial, sans-serif;
    padding: 0 5px;
    position: absolute;
    top: -1em;
    left: 0;
}
 
.dokuwiki .page h1:hover span.wikiLink,
.dokuwiki .page h2:hover span.wikiLink,
.dokuwiki .page h3:hover span.wikiLink,
.dokuwiki .page h4:hover span.wikiLink,
.dokuwiki .page h5:hover span.wikiLink {
    display: block;
}

Known restrictions

  • Needs the class “page” around the main content in the template (like in the default template).
tips/copy_section_link.txt · Last modified: 2010/11/21 16:53 by ach
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 3.0 Unported
Imprint Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki
WikiForumIRCBugsGitXRefTranslate