1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
var WebDeveloper = WebDeveloper || {};
WebDeveloper.Generated = WebDeveloper.Generated || {};
// Initializes the page with data
WebDeveloper.Generated.initialize = function(data, locale)
{
var childElement = null;
var container = null;
var content = document.getElementById("content");
var contentDocument = null;
var documentOutline = locale.documentOutline;
var documents = data.documents;
var heading = null;
var headingDescription = null;
var headingLevel = null;
var headings = null;
var headingsLength = null;
var headingText = null;
var previousHeadingLevel = null;
WebDeveloper.Generated.emptyContent();
WebDeveloper.Generated.localizeHeader(locale);
WebDeveloper.Generated.setPageTitle(documentOutline, data, locale);
// Loop through the documents
for(var i = 0, l = documents.length; i < l; i++)
{
contentDocument = documents[i];
headingDescription = locale.headings.toLowerCase();
headings = contentDocument.headings;
headingsLength = headings.length;
// If there is only one heading
if(headingsLength == 1)
{
headingDescription = locale.heading.toLowerCase();
}
WebDeveloper.Generated.addDocument(contentDocument.url, i, headingDescription, headingsLength);
// If there are headings
if(headingsLength > 0)
{
container = WebDeveloper.Generated.generateDocumentContainer();
previousHeadingLevel = 0;
// Loop through the headings
for(var j = 0; j < headingsLength; j++)
{
heading = headings[j];
headingLevel = heading.level;
headingText = heading.text;
// Loop through any missing headers
for(var k = previousHeadingLevel + 1; k < headingLevel; k++)
{
childElement = document.createElement("span");
heading = document.createElement("h" + k);
childElement.appendChild(document.createTextNode("<h" + k + ">"));
childElement.setAttribute("class", "label label-warning");
heading.appendChild(childElement);
heading.appendChild(document.createTextNode(locale.missingHeading));
heading.setAttribute("class", "web-developer-missing-heading");
container.appendChild(heading);
}
// If there is no heading text
if(!headingText)
{
headingText = locale.noHeadingText;
}
childElement = document.createElement("span");
heading = document.createElement("h" + headingLevel);
childElement.appendChild(document.createTextNode("<h" + headingLevel + ">"));
childElement.setAttribute("class", "label label-success");
heading.appendChild(childElement);
heading.appendChild(document.createTextNode(headingText));
container.appendChild(heading);
previousHeadingLevel = headingLevel;
}
content.appendChild(container);
}
WebDeveloper.Generated.addSeparator();
}
WebDeveloper.Generated.initializeCommonElements();
};
|