%
var output = "";
var pageModule = page;
var hasTag = page.hasTag;
var slug = env.slug;
var locale = env.locale;
var baseURL = "/" + locale + "/docs/";
var baseAPIPage = baseURL + "Mozilla/Add-ons/WebExtensions/API";
var escapeQuotes = mdn.escapeQuotes;
var htmlEscape = kuma.htmlEscape;
var rtlLocales = ['ar', 'he', 'fa'];
let commonl10n = string.deserialize(await template('L10n:Common'));
let text = {
'translate': mdn.getLocalString(commonl10n, '[Translate]'),
'title': mdn.getLocalString(commonl10n, 'TranslationCTA'),
'Methods': mdn.getLocalString(commonl10n, 'Methods'),
'Properties': mdn.getLocalString(commonl10n, 'Properties'),
'Types': mdn.getLocalString(commonl10n, 'Types'),
'Events': mdn.getLocalString(commonl10n, 'Events'),
};
var badges = {
ExperimentalBadge : '',
NonStandardBadge : '',
DeprecatedBadge : '',
ObsoleteBadge : '',
}
function buildSublist(pages, title, ignoreBadges) {
var result = '
' + title + '';
for (var i in pages) {
var aPage = pages[i];
var summary = escapeQuotes(aPage.summary) || '';
var url = aPage.url.replace('en-US', locale);
var title = htmlEscape(aPage.title);
var apiComponentName = title;
var titlePieces = title.split(".");
if (titlePieces.length > 1) {
apiComponentName = titlePieces[1];
}
var translated = false;
if (locale != 'en-US') {
aPage.translations.forEach(function(translation) {
if(translation.locale === locale) {
summary = escapeQuotes(translation.summary) || '';
url = translation.url;
title = htmlEscape(translation.title);
translated = true;
}
});
}
var cta = '';
if (!translated && locale != 'en-US') {
cta += ' ' + text['translate'] + '';
}
result += '- ';
if (!ignoreBadges) {
if (hasTag(aPage, 'Experimental')) {
result += badges.ExperimentalBadge;
}
if (hasTag(aPage, 'Non-standard') || hasTag(aPage, 'Non Standard')) {
result += badges.NonStandardBadge;
}
if (hasTag(aPage, 'Deprecated')) {
result += badges.DeprecatedBadge;
}
if (hasTag(aPage, 'Obsolete')) {
result += badges.ObsoleteBadge;
result += '
';
}
}
if (rtlLocales.indexOf(locale) != -1) {
result += '';
}
if (slug == aPage.slug) {
result += '' + apiComponentName + ''
} else {
result += '' + apiComponentName + '' + cta;
}
if (rtlLocales.indexOf(locale) != -1) {
result += '';
}
if (hasTag(aPage, 'Obsolete')) {
result += '';
}
result += ' ';
}
result += '
';
return result;
}
function classifyPages(subpages) {
var collection = {
properties: [],
methods: [],
events: [],
types: []
}
subpages.forEach(function(subpage) {
if (hasTag(subpage, "Property")) {
collection.properties.push(subpage);
}
if (hasTag(subpage, "Method")) {
collection.methods.push(subpage);
}
if (hasTag(subpage, "Type")) {
collection.types.push(subpage);
}
if (hasTag(subpage, "Event")) {
collection.events.push(subpage);
}
});
return collection;
}
async function buildSidebarForSingleAPI(apiPath) {
output+= '';
var subpages = await pageModule.subpagesExpand(apiPath);
var pageCollection = classifyPages(subpages);
if (pageCollection.methods.length > 0) {
output += buildSublist(pageCollection.methods, text["Methods"], true);
}
if (pageCollection.properties.length > 0) {
output += buildSublist(pageCollection.properties, text["Properties"], true);
}
if (pageCollection.types.length > 0) {
output += buildSublist(pageCollection.types, text["Types"], true);
}
if (pageCollection.events.length > 0) {
output += buildSublist(pageCollection.events, text["Events"], true);
}
output += '
';
}
async function buildSidebarForAllAPIs() {
output = "";
var browserSupportURL = baseURL + "Mozilla/Add-ons/WebExtensions/Browser_support_for_JavaScript_APIs";
var browserSupportTitle = "Browser support for JavaScript APIs";
output += '- ' + browserSupportTitle + '';
var subpages = await pageModule.subpagesExpand(baseAPIPage);
for (var i = 0; i < subpages.length; i++) {
var apiPage = subpages[i];
var pieces = apiPage.url.split("/");
var apiName = pieces.slice(-1);
if (slug.indexOf(apiPage.slug) != -1) {
output += '
- ' + apiName + '';
}
output += '
';
}
output += '
';
}
await buildSidebarForAllAPIs(baseURL);
%>
<%-output%>