Revision 467869 of Template:APIRef

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

Revision Content

<% // Creates a link to the interface on which this page is a method or property. // // Parameters: // $0 The name of the interface this page belongs to. 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; } s_str0 = $0; s_str1 = $0; var s_api_href = '/' + env.locale + '/docs/Web/API'; var aquo = "«"; // "»" /* For RTL locales (ar, he, ...) */ switch(env.locale) { case "ar": case "he": aquo = "»"; // "«" break; default: } var result = '' + aquo + ' ' + s_str1 + ''; %><%- result%> <% /* Generate quick links */ /* Find the API Name from the URL: the part after the last / and before the first . */ var pageURL = page.href. 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); /* Add to the list, the one that are listed in parameter: hierarchy */ /* Add to the list, those that are implemented by it */ /* List properties of this API */ // Find the pages, sub-pages of CSS/ that are tagged with that specific tag var pageList = page.subpagesExpand(s_api_href); // Get subpages, including tags var resultProps = []; for (aPage in pageList) { if (containsAPI(APIList, pageList[aPage].href) && containsTag(pageList[aPage].tags, "Properties")) { // We only want properties resultProps.push(pageList[aPage].title); } } /* Find the constructor of this API */ /* List methods of this API */ var resultMethods = []; for (aPage in pageList) { if (containsAPI(APIList, pageList[aPage].href) && containsTag(pageList[aPage].tags, "Methods") && !containsTag(pageList[aPage].tags, "Constructor")) { // We only want methods resultMethods.push(pageList[aPage].title); } } %>
    <% /* Display ancestor chain */ // TBD: the chain, we only displays the lowest one! %>
  1. <%-mainIF%>
  2. <% /* Display properties */ for (aProp in resultProps) { %>
  3. <%- template("domxref", [resultProps[aProp], resultProps[aProp].split('.')[1]]) %>
  4. <% } /* Display constructor */ // TBD. /* Display methods */ for (aMethod in resultMethods) { %>
  5. <%- template("domxref", [resultMethods[aMethod], resultMethods[aMethod].split('.')[1]]) %>
  6. <% } } else {%>"bouh"<%} %>

Revision Source

<%
// Creates a link to the interface on which this page is a method or property.
//
// Parameters:
//  $0  The name of the interface this page belongs to.

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;
}

s_str0 = $0;
s_str1 = $0;
var s_api_href = '/' + env.locale + '/docs/Web/API';

var aquo = "&laquo;";   // "»"

/*
 For RTL locales (ar, he, ...)
*/
switch(env.locale) {
    case "ar":
    case "he":
        aquo = "&raquo;";   // "«"
        break;
    default:
}

var result = '<span  class="breadcrumbs themeUpdated">' + aquo + '&nbsp;<a href="/' + env.locale + '/docs/Web/API/' + s_str0 + '">' + s_str1 + '</a></span>';

%><%- result%>
<%


/* Generate quick links */

    /* Find the API Name from the URL: the part after the last / and before the first . */
    var pageURL = page.href.
    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);
    /* Add to the list, the one that are listed in parameter: hierarchy */
    
    /* Add to the list, those that are implemented by it */

    /* List properties of this API */
    // Find the pages, sub-pages of CSS/ that are tagged with that specific tag
    var pageList = page.subpagesExpand(s_api_href);   // Get subpages, including tags
    var resultProps = [];

    for (aPage in pageList) {
        if (containsAPI(APIList, pageList[aPage].href) &&
            containsTag(pageList[aPage].tags, "Properties")) { // We only want properties
            resultProps.push(pageList[aPage].title);
        }
    }

    /* Find the constructor of this API */

    /* List methods of this API */
    var resultMethods = [];

    for (aPage in pageList) {
        if (containsAPI(APIList, pageList[aPage].href) &&
            containsTag(pageList[aPage].tags, "Methods") &&
            !containsTag(pageList[aPage].tags, "Constructor")) { // We only want methods
            resultMethods.push(pageList[aPage].title);
        }
    }
    %>
<h2 class="Quick_links" id="Quick_Links">Quick Links</h2>
  <ol>
    <%
    /* Display ancestor chain */
    // TBD: the chain, we only displays the lowest one!
    %>
    <li><a href="<%- s_api_href + '/' + mainIF%>"><%-mainIF%></a></li>
    <%
    /* Display properties */
    for (aProp in resultProps) { 
    %>
        <li><%- template("domxref", [resultProps[aProp], resultProps[aProp].split('.')[1]]) %></li>
<%  } 
    /* Display constructor */
    // TBD.

    /* Display methods */
    for (aMethod in resultMethods) { 
    %>
        <li><%- template("domxref", [resultMethods[aMethod], resultMethods[aMethod].split('.')[1]]) %></li>
<%  } } else {%>"bouh"<%}
%>
    </ol>