Template:APIRef

  • Revision slug: Template:APIRef
  • Revision title: Template:APIRef
  • Revision id: 490907
  • Created:
  • Creator: fscholz
  • Is current revision? No
  • Comment

Revision Content

<% // Creates a link to the interface on which this page is a method or property. // // Parameters: // $0 A specific tag to releated APIs (or the API name for backward compatibility) function containsTag(tagList, tag) { if (!tagList || tagList == undefined) return 0; tag = tag.toLowerCase(); for (var i = 0, len = tagList.length; i < len; i++) { if (tagList[i].toLowerCase() === tag) return 1; } return 0; } function containsAPI(APIList, name) { name = name.toLowerCase(); name = name.split('.')[0]; for (var i = 0, len = APIList.length; i < len; i++) { if (APIList[i].toLowerCase() === name) { return 1; } } return 0; } var s_api_tag = $0; var s_api_href = '/' + env.locale + '/docs/Web/API'; var s_api_title_methods = mdn.localString({ "en-US": "Methods", "fr" : "Méthodes", "de" : "Methoden" }); var s_api_title_properties = mdn.localString({ "en-US": "Properties", "fr" : "Propriétés", "de" : "Eigenschaften" }); var s_api_title_seealso = mdn.localString({ "en-US": "Related APIs", "fr" : "API connexes", "de" : "Verwandte APIs" }); var aquo = mdn.localString({ "en-US": "«", // "»" // For RTL locales (ar, he, ...) "ar" : "»", // "«" "he" : "»", // "«" }); /* Find the API Name from the URL: the part after the last / and before the first . */ var pageURL = env.path; var pageFolders = pageURL.split('/'); if (pageFolders) { var pageName = pageFolders[pageFolders.length-1]; // We are only interested in the last part var mainIF = pageName.split('.')[0]; var APIList = []; APIList.push(mainIF); var pageList = page.subpagesExpand(s_api_href); // Get subpages, including tags /* List properties of this API */ var resultProps = []; /* List methods of this API */ var resultMethods = []; /* List related APIs */ var resultSeealso = []; for (aPage in pageList) { if (containsAPI(APIList, pageList[aPage].title)) { if(containsTag(pageList[aPage].tags, "Property")) { // We only want properties pageList[aPage].domxref = template("domxref", [pageList[aPage].title]); resultProps.push(pageList[aPage]); } if (containsTag(pageList[aPage].tags, "Method") && !containsTag(pageList[aPage].tags, "Constructor")) { // We only want methods pageList[aPage].domxref = template("domxref", [pageList[aPage].title]); resultMethods.push(pageList[aPage]); } } if (containsTag(pageList[aPage].tags, s_api_tag) && pageList[aPage].title.indexOf('.') === -1 && pageList[aPage].title !== mainIF) { pageList[aPage].domxref = template("domxref", [pageList[aPage].title]); resultSeealso.push(pageList[aPage]); } } } var badges = { ExperimentalBadge : '' + template("ExperimentalBadge", [1]) + '', NonStandardBadge : '' + template("NonStandardBadge", [1]) + '', DeprecatedBadge : '' + template("DeprecatedBadge", [1]) + '', ObsoleteBadge : '' + template("ObsoleteBadge", [1]) + '', } function buildSublist(pages, title) { var result = '
  • ' + title + '
      '; for (aPage in pages) { result += '
    1. '; log.debug(pages[aPage]); if (containsTag(pages[aPage].tags, 'Experimental')) { result += badges.ExperimentalBadge; } if (containsTag(pages[aPage].tags, 'Non-standard') || containsTag(resultProps[aPage].tags, 'Non Standard')) { result += badges.NonStandardBadge; } if (containsTag(pages[aPage].tags, 'Deprecated')) { result += badges.DeprecatedBadge; } if (containsTag(pages[aPage].tags, 'Obsolete')) { result += badges.ObsoleteBadge; } result += '' + pages[aPage].domxref + '
    2. '; } result += '
  • '; return result; } %> <%- aquo %> <%= mainIF %>

    Revision Source

    <%
    // Creates a link to the interface on which this page is a method or property.
    //
    // Parameters:
    //  $0  A specific tag to releated APIs (or the API name for backward compatibility)
    
    function containsTag(tagList, tag) {
        if (!tagList || tagList == undefined) return 0;
        tag = tag.toLowerCase();
        for (var i = 0, len = tagList.length; i < len; i++) {
            if (tagList[i].toLowerCase() === tag) return 1;
        }
        return 0;
    }
    
    function containsAPI(APIList, name) {
        name = name.toLowerCase();
        name = name.split('.')[0];
        for (var i = 0, len = APIList.length; i < len; i++) {
            if (APIList[i].toLowerCase() === name) {
                return 1;
            }
        }
        return 0;
    }
    
    var s_api_tag  = $0;
    var s_api_href = '/' + env.locale + '/docs/Web/API';
    
    var s_api_title_methods = mdn.localString({
      "en-US": "Methods",
      "fr"   : "Méthodes",
      "de"   : "Methoden"
    });
    
    var s_api_title_properties = mdn.localString({
      "en-US": "Properties",
      "fr"   : "Propriétés",
      "de"   : "Eigenschaften"
    });
    
    var s_api_title_seealso = mdn.localString({
      "en-US": "Related APIs",
      "fr"   : "API connexes",
      "de"   : "Verwandte APIs"
    });
    
    var aquo = mdn.localString({
      "en-US": "&laquo;", // "»"
     
      // For RTL locales (ar, he, ...)
      "ar"   : "&raquo;", // "«"
      "he"   : "&raquo;", // "«"
    });
    
    /* Find the API Name from the URL: the part after the last / and before the first . */
    var pageURL = env.path;
        
    var pageFolders = pageURL.split('/');
    if (pageFolders) {
        var pageName = pageFolders[pageFolders.length-1]; // We are only interested in the last part
        var mainIF = pageName.split('.')[0];
        var APIList = [];
        APIList.push(mainIF);
    
        var pageList = page.subpagesExpand(s_api_href);   // Get subpages, including tags
        
        /* List properties of this API */
        var resultProps = [];
        
        /* List methods of this API */
        var resultMethods = [];
    
        /* List related APIs */
        var resultSeealso = [];
    
        for (aPage in pageList) {
            if (containsAPI(APIList, pageList[aPage].title)) {
                if(containsTag(pageList[aPage].tags, "Property")) { // We only want properties
                    pageList[aPage].domxref = template("domxref", [pageList[aPage].title]);
                    resultProps.push(pageList[aPage]);
                }
                
                if (containsTag(pageList[aPage].tags, "Method") &&
                !containsTag(pageList[aPage].tags, "Constructor")) { // We only want methods
                    pageList[aPage].domxref = template("domxref", [pageList[aPage].title]);
                    resultMethods.push(pageList[aPage]);
                }
            }
            
            if (containsTag(pageList[aPage].tags, s_api_tag) &&
            pageList[aPage].title.indexOf('.') === -1 &&
            pageList[aPage].title !== mainIF) {
                pageList[aPage].domxref = template("domxref", [pageList[aPage].title]);
                resultSeealso.push(pageList[aPage]);
            }
        }
    }
    
    var badges = {
        ExperimentalBadge : '<span class="sidebar-icon">' + template("ExperimentalBadge", [1]) + '</span>',
        NonStandardBadge  : '<span class="sidebar-icon">' + template("NonStandardBadge", [1]) + '</span>',
        DeprecatedBadge   : '<span class="sidebar-icon">' + template("DeprecatedBadge", [1]) + '</span>',
        ObsoleteBadge     : '<span class="sidebar-icon">' + template("ObsoleteBadge", [1]) + '</span>',
    }
    
    function buildSublist(pages, title) {
        var result = '<li data-default-state="open"><a href="#"><strong>' + title + '</strong></a><ol>';
        
        for (aPage in pages) {
            result += '<li>';
            log.debug(pages[aPage]);
            
            if (containsTag(pages[aPage].tags, 'Experimental')) {
                result += badges.ExperimentalBadge;
            }
            
            if (containsTag(pages[aPage].tags, 'Non-standard') ||
            containsTag(resultProps[aPage].tags, 'Non Standard')) {
                result += badges.NonStandardBadge;
            }
            
            if (containsTag(pages[aPage].tags, 'Deprecated')) {
                result += badges.DeprecatedBadge;
            }
            
            if (containsTag(pages[aPage].tags, 'Obsolete')) {
                result += badges.ObsoleteBadge;
            }
            
            result += '<em>' + pages[aPage].domxref + '</em></li>';
        }
        
        result += '</ol></li>';
        
        return result;
    }
        
    %>
    <span class="breadcrumbs themeUpdated"><%- aquo %>&nbsp;<a href="<%- s_api_href + '/' + mainIF %>"><%= mainIF %></a></span>
    <section class="Quick_links" id="Quick_Links">
      <ol>
        <%
        /* Display ancestor chain */
        // TBD: the chain, we only displays the lowest one!
        %>
        <li><strong><%- template("domxref", [mainIF]) %></a></strong></li>
        <% 
        
        /* Display properties */ 
        if (resultProps.length > 0) { 
            %><%-buildSublist(resultProps, s_api_title_properties)%><%
        }
        
        /* Display methods */ 
        if (resultMethods.length > 0) {
            %><%-buildSublist(resultMethods, s_api_title_methods)%><%
        }
        
        /* Display related APIs */
        if (resultSeealso.length > 0) {
            %><%-buildSublist(resultSeealso, s_api_title_seealso)%><%
        }
        %>
      </ol>
    </section>
    Revert to this revision