Github user dblotsky commented on a diff in the pull request:

    https://github.com/apache/cordova-docs/pull/487#discussion_r52270223
  
    --- Diff: www/static/js/docs.js ---
    @@ -17,49 +17,81 @@
     
     $(document).ready(function () {
     
    -    function getAnchorName(i, heading, prefix) {
    -        var name = prefix;
    +    function slugify(text) {
    +        text = text.toLowerCase();
    +
    +        // replace unaccepted characters with spaces
    +        // NOTE:
    +        //      a better regex would have been /[^\d\s\w]/ug, but the 'u' 
flag
    +        //      (Unicode) is not supported in some browsers, and we support
    +        //      many languages that use Unicode characters
    +        text = text.replace(/[\[\]\(\)\=\+\?]/g, ' ');
    +
    +        // trim whitespace and replace runs of whitespace with single 
dashes
    +        text = text.trim().replace(/ +/g, '-');
    +
    +        return text;
    +    }
    +
    +    function getIdForHeading(heading) {
             if (heading.id) {
    -            name += heading.id;
    +            return heading.id;
             } else if (heading.name) {
    -            name += heading.name;
    +            return heading.name;
             } else {
    -            name += i;
    +            return slugify(heading.innerText);
             }
    -        return name;
         }
     
    -    var anchorLink = function (id) {
    -        var anchor = document.createElement("a");
    +    function permalinkTo(id) {
    +        var anchor       = document.createElement("a");
             anchor.className = "header-link";
             anchor.href      = "#" + id;
             anchor.innerHTML = "<i class=\"glyphicon glyphicon-link\"></i>";
             return anchor;
         }
     
    +    function anchorFor(id) {
    +        var anchor       = document.createElement("a");
    +        anchor.className = "fragment-anchor";
    +        anchor.id        = id;
    +        return anchor;
    +    }
    +
    +    // go through all headings in the content and add some links
    +    $('#page-toc-source h1, #page-toc-source h2').each(function (i, 
heading) {
    +
    +        headingId = getIdForHeading(heading);
    +
    +        // add an anchor for linking to the heading
    +        // NOTE:
    +        //      we could have set the ID on the heading itself but we 
didn't
    +        //      because the <a> has some extra CSS that floats it above the
    +        //      heading and makes it easier to see when linked
    +        $(heading).before(anchorFor(headingId))
    +
    +        // add a permalink to all but the first heading
    +        if (i > 0) {
    +            $(heading).append(permalinkTo(headingId));
    +        }
    +    });
    +
         // Table of Contents
         $('#page-toc').toc({
             'selectors':         'h1,h2', // elements to use as headings
             'container':         '#page-toc-source', // element to find all 
selectors in
    -        'prefix':            'link-', // prefix for anchor tags and class 
names
    +        'prefix':            'toc-', // prefix for anchor tags and class 
names
    --- End diff --
    
    Yep, I removed it from the code. I'll make it empty to make that more clear.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@cordova.apache.org
For additional commands, e-mail: dev-h...@cordova.apache.org

Reply via email to