⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 displaytoc.js

📁 一个真正的CMS系统,可以完全实现建站自动化,用.NET开发.
💻 JS
📖 第 1 页 / 共 2 页
字号:
            tocFrame.document.writeln("<td nowrap colspan=" + (nCols-thisLevel) + ">");
            tocFrame.document.writeln("<p " +
                                  "onMouseDown=\"top.reDisplay('" + thisNumber + "', " + tocBehaviour[1] + "," + tocLinks[1] + ",event)\" " +
                                  "onMouseOver=\"status='" + tocTab[i][2] + "'; return true;\" " +
                                  "title=\"" + tocTab[i][1] + "\" " +
                                  "style=\" " +
                                     "font-family:" + fontLines + "; " +
                                     ((thisLevel<=mLevel)?"font-weight:bold; ":"") + 
                                     "font-size:" + ((thisLevel<=mLevel)?mdi:sml) + "em; " +
                                     "color:" + thisTextColor + "; " +
                                     "background-color:" + thisBgColor + "; " +
                                     "cursor: pointer;" +
                                  "\">");
            tocFrame.document.write("" + ((showNumbers)?(thisNumber+" "):"") + tocTab[i][1]);
            tocFrame.document.write("</p>");
            tocFrame.document.write("</td>");
            tocFrame.document.writeln("</tr>");
        }
    } // End of loop over the tocTab

    /*
     * Closing the ToC document, scrolling its frame window and displaying new content
     * in the content frame or in the top window if required 
     */

    /*
     * Updating the global variables oldCurrentNumber and oldLastVisitNumber. See above
     * for its definition
     */
    if (tocChange) { 
//        oldLastVisitNumber = oldCurrentNumber;
//        oldCurrentNumber = currentNumber;
//
// use cookies to store the state instead of variables
        setCookie("currentTOCTopic", currentNumber);
        setCookie("previousTOCTopic", oldCurrentNumber);
    }

    /*
     * Closing the ToC table and the document
     */
    tocFrame.document.writeln("</table>\n</body></html>");
    tocFrame.document.close();

    /*
     * Scrolling the ToC if required
     */
    if (tocScroll)
    {
        tocFrame.scroll(0,scrollY);
    }
    
    /*
     * Setting the top or content window's location if required
     */
    if (theHref) 
    {
        if (theTarget=="top")
        {
            window.top.location.href = theHref;
        }
        else if (theTarget=="parent") 
        {
            window.parent.location.href = theHref;
        }
        else if (theTarget=="blank")
        {
            window.open(theHref,"");
        }
        else
        {
            var newLocation = appendQuery(theHref, '?skipReload=true');

            // if we're displaying the top topic, use replace so it doesn't
            // go in the history.  otherwise use location=url so it does
            // go in the history.
            if( currentNumber == "0" )
            {
              debug('reDisplay: contentFrame.location.replace(' +
                        newLocation + ')');
              contentFrame.location.replace(newLocation);
            }
            else
            {
              debug('reDisplay: contentFrame.location=' +
                        newLocation);
              contentFrame.location = newLocation;
            }
        }
    }
}

//
// strip off the leading part of the URL and leave only the last
//  couple of directory names and filename. 
//
function trimTopicURL(url)
{
    if (url != null)
    {
        topic = url;

        // find the / before the filename, if any
        var index = topic.lastIndexOf('/');
        if (index != -1)
        {
            index = topic.lastIndexOf('/', index-1);
        }

        // find the / before the last dir name, if any
        if (index != -1)
        {
            index = topic.lastIndexOf('/', index-1);
        }

        // find the / before the second to last dir name, if any
//        if (index != -1)
//        {
//            index = topic.lastIndexOf('/', index-1);
//        }

        // find the / before the third to last dir name, if any
//        if (index != -1)
//        {
//            index = topic.lastIndexOf('/', index-1);
//        }

        // grab the substring starting at the earliest slash found
        if (index != -1)
        {
            topic = topic.substring(index+1);
        }

        // strip off the fragment, if any
        index = topic.lastIndexOf('#');
        if (index != -1)
        {
            topic = topic.substring(0, index);
        }
        return topic;
    }
    else
    {
        return url;
    }
}
 
function findTopicNumber(targetUrl)
{ 
    // initialize to top-level topic be default
    var topicNumber = tocTab[0][0];

    //
    // The loop below will search the TOC for "url" attributes that contain
    // the target URL as a substring. We want the search string to be short
    // but still probably unique in the TOC.
    //
//    if (url != null)
//    {
//        var topic = trimTopicURL(url);
//        
//        for(i=0;  i<tocTab.length; i++)
//        {
//            if( tocTab[i][2].indexOf(topic) != -1 )
//            {
//                topicNumber = tocTab[i][0];
//                break;
//            }
//        }
//    }

    //
    // NOTE: the technique below is pretty expensive compared to the simple
    // indexOf compare above (old technique). it may need to be removed for
    // that reason if perf is bad.
    //
    // we want to find the targetUrl in the TOC. The targetUrl is likely to be an
    // absolute URL like
    //
    //   C:/somedir/help/doc/en/portal/buildportals/createCampaigns.html
    //
    // and the candidate URLs in the TOC are likely to be relative URLs like
    //
    //   ../portal/buildportals/createCampaigns.html
    //
    // In the case above, the algorithm below would find "portal" as the first
    // "real" segment in the candidate URL and then look for that segment in the
    // target URL (looping in case the segment occurs more than
    // once in the targetUrl). If the segment occurs in the targetUrl, then
    // look for the substring of the targetUrl beginning at the segment as a
    // substring of the candidate URL.  I.e., see if
    //
    //   portal/buildportals/createCampaigns.html
    //
    // occurs as a substring of
    //
    //   ../portal/buildportals/createCampaigns.html
    //
    // if it does, we've found a match.
    //
    if( targetUrl != null )
    {
        var found = false;
        var candidateUrl;
        var candidateSegments;
        var firstSegments;
        var numSegments;
        var segment;
        var index;
        var start;
        var i;
        var trimmedTargetUrl;

        // strip off the fragment, if any
        index = targetUrl.lastIndexOf('#');
        if (index != -1)
        {
            trimmedTargetUrl = targetUrl.substring(0, index);
        }
        else
        {
            trimmedTargetUrl = targetUrl;
        }

        // loop over all TOC nodes
        for(i=0; i<tocTab.length; i++)
        {

            // candidateUrl is the value of the url attribute for this TOC node
            candidateUrl = tocTab[i][2];
            candidateSegments = candidateUrl.split("/");
            numSegments = candidateSegments.length;

            // find the first real segment, ignoring empty segments and . and .. segments
            segment = 0;
            while( (segment < numSegments) &&
                   ((candidateSegments[segment] == "") ||
                     (candidateSegments[segment] == ".") ||
                     (candidateSegments[segment] == "..")) )
            {
                segment++;
            }
            if( segment < numSegments )
            {
                firstSegment = candidateSegments[segment];

                // see if the targetUrl contains the first segment of the candidateUrl
                start = 0;
                while( !found && ((index = targetUrl.indexOf(firstSegment, start)) != -1) )
                {
                    // if the targetUrl contains the first segment
                    // of the candidateUrl, then see if the candidateUrl contains as a
                    // substring the entire remaining targetUrl (trimmed of any #fragment)
                    if( candidateUrl.indexOf(trimmedTargetUrl.substring(index)) != -1)
                    {
                        found = true;
                        break;
                    }
                    start = index + 1;
                }
                if( found )
                {
                    break;
                }
            }
        }
        if( found )
        {
            topicNumber = tocTab[i][0];
        }
    }
    
    return topicNumber;
}

function displayTOC()
{
    var topicNumber = "0";
    var url;
    
    // First, try to read data stored in the cookie. If the cookie is not
    // defined display the top level help topic.
    var destTOC = new Cookie(document, "destTOC");
    if (destTOC.load())
    {
        url = unescape(destTOC.url);
        if (url != null)
        {        
            topicNumber = findTopicNumber(url);
        }
        destTOC.remove();
    }

    // if we're displaying the top level topic, force content display,
    // otherwise, let content.html take care of it.
    if ((topicNumber.length == 1) && (topicNumber.indexOf("0") == 0))
    {
        reDisplay(topicNumber, 2, true);
    }
    else
    {
        reDisplay(topicNumber, 2, false);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -