Template:APIRef

  • Revision slug: Template:APIRef
  • Revision title: Template:APIRef
  • Revision id: 490213
  • Created:
  • Creator: Jeremie
  • 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 resultProps.push(pageList[aPage]); } if (containsTag(pageList[aPage].tags, "Method") && !containsTag(pageList[aPage].tags, "Constructor")) { // We only want methods resultMethods.push(pageList[aPage]); } } if (containsTag(pageList[aPage].tags, s_api_tag) && pageList[aPage].title.indexOf('.') === -1 && pageList[aPage].title !== mainIF) { resultSeealso.push(pageList[aPage]); } } } // This is a workaround to avoid a strange Kumascript bug var fn_template = template.bind(this); function buildBadge(name) { return '' + fn_template(name, [1]) + ''; } function buildSublist(pages, title) { var result = '
  • ' + title + '
      '; for (aPage in pages) { result += '
    1. '; if (containsTag(resultProps[aPage].tags, 'Experimental')) { result += buildBadge("ExperimentalBadge"); } if (containsTag(resultProps[aPage].tags, 'Non-standard') || containsTag(resultProps[aPage].tags, 'Non Standard')) { result += buildBadge("NonStandardBadge"); } if (containsTag(resultProps[aPage].tags, 'Deprecated')) { result += buildBadge("DeprecatedBadge"); } if (containsTag(resultProps[aPage].tags, 'Obsolete')) { result += buildBadge("ObsoleteBadge"); } result += '' + fn_template("domxref", [pages[aPage].title]) + '
    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
                    resultProps.push(pageList[aPage]);
                }
                
                if (containsTag(pageList[aPage].tags, "Method") &&
                !containsTag(pageList[aPage].tags, "Constructor")) { // We only want methods
                    resultMethods.push(pageList[aPage]);
                }
            }
            
            if (containsTag(pageList[aPage].tags, s_api_tag) &&
            pageList[aPage].title.indexOf('.') === -1 &&
            pageList[aPage].title !== mainIF) {
                resultSeealso.push(pageList[aPage]);
            }
        }
    }
    
    // This is a workaround to avoid a strange Kumascript bug 
    var fn_template = template.bind(this);
    
    function buildBadge(name) {
        return '<span class="sidebar-icon">' + fn_template(name, [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>';
            
            if (containsTag(resultProps[aPage].tags, 'Experimental')) {
                result += buildBadge("ExperimentalBadge");
            }
            
            if (containsTag(resultProps[aPage].tags, 'Non-standard') ||
            containsTag(resultProps[aPage].tags, 'Non Standard')) {
                result += buildBadge("NonStandardBadge");
            }
            
            if (containsTag(resultProps[aPage].tags, 'Deprecated')) {
                result += buildBadge("DeprecatedBadge");
            }
            
            if (containsTag(resultProps[aPage].tags, 'Obsolete')) {
                result += buildBadge("ObsoleteBadge");
            }
            
            result += '<em>' + fn_template("domxref", [pages[aPage].title]) + '</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) {
        %>
        <li data-default-state="open"><a href="#"><strong><%=s_api_title_methods%></strong></a>
        <ol>
        <% for (aPage in resultMethods) { %>
            <li>
            <% if (containsTag(resultMethods[aPage].tags, 'Experimental')) { %>
                <span class="sidebar-icon"><%-template("ExperimentalBadge", [1])%></span>
            <% } %>
            <% if (containsTag(resultMethods[aPage].tags, 'Non-standard') ||
                   containsTag(resultMethods[aPage].tags, 'Non Standard')) { %>
                 <span class="sidebar-icon"><%-template("NonStandardBadge", [1])%></span>
            <% } %>
            <% if (containsTag(resultMethods[aPage].tags, 'Deprecated')) { %>
                 <span class="sidebar-icon"><%-template("DeprecatedBadge", [1])%></span>
            <% } %>
            <% if (containsTag(resultMethods[aPage].tags, 'Obsolete')) { %>
                 <span class="sidebar-icon"><%-template("ObsoleteBadge", [1])%></span>
            <% } %>
            <em><%- template("domxref", [resultMethods[aPage].title]) %></em></li>
        <%  } %>
        </ol></li>
        <% 
        }
        
        /* Display related APIs */
        if (resultSeealso.length > 0) {
        %>
        <li data-default-state="open"><a href="#"><strong><%=s_api_title_seealso%></strong></a>
        <ol>
        <% for (aPage in resultSeealso) { %>
            <li>
            <% if (containsTag(resultSeealso[aPage].tags, 'Experimental')) { %>
                <span class="sidebar-icon"><%-template("ExperimentalBadge", [1])%></span>
            <% } %>
            <% if (containsTag(resultSeealso[aPage].tags, 'Non-standard') ||
                   containsTag(resultSeealso[aPage].tags, 'Non Standard')) { %>
                 <span class="sidebar-icon"><%-template("NonStandardBadge", [1])%></span>
            <% } %>
            <% if (containsTag(resultSeealso[aPage].tags, 'Deprecated')) { %>
                 <span class="sidebar-icon"><%-template("DeprecatedBadge", [1])%></span>
            <% } %>
            <% if (containsTag(resultSeealso[aPage].tags, 'Obsolete')) { %>
                 <span class="sidebar-icon"><%-template("ObsoleteBadge", [1])%></span>
            <% } %>
            <em><%- template("domxref", [resultSeealso[aPage].title]) %></em></li>
        <%  } %>
        </ol></li>
        <%
        }
        %>
      </ol>
    </section>
    Revert to this revision