summaryrefslogtreecommitdiffstats
path: root/common/html-coverpage/static/rtems/js/catalogue.js
blob: ae32aed4f2dabe9dbcb41b6e2597003e00b1d732 (plain) (blame)
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
/*!
 * Catalogue 0.1
 * Copyright 2017 Chris Johns <chrisj@rtems.org>
 * Licensed under the MIT license
 */

function parseCatalogue(xml) {
    if (window.DOMParser)
    {
        parser = new DOMParser();
        xmlDoc = parser.parseFromString(xml, "text/xml");
    }
    else // Internet Explorer
    {
        xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
        xmlDoc.async = false;
        xmlDoc.loadXML(xml);
    }
    return xmlDoc;
}

function catalogueHeader(date) {
    return '<table class="table table-condensed table-nonfluid">\n' +
	' <tbody>\n' +
	'  <thead><tr><th>Built: ' + date + '</th><th>PDF</th><th>Single Page</th></tr></thead>\n';
}
function catalogueFooter() {
    return ' </tbody>\n' +
	'</table>\n';
}

function paintCatalogue(xml) {
    var el_cat_title = $('#rtems-catalogue-title');
    var el_cat = $('#rtems-catalogue');
    /*
     * Use jquery as XMLDocument is consider not stable on Firefox's web site.
     */
    var pdfIcon = 'static/images/Adobe_PDF_file_icon_32x32.png';
    var htmlIcon = 'static/images/html-xxl.png';
    var docs = $(xml).find('rtems-docs');
    var date = $(docs).attr('date');
    var title = $(docs).find('catalogue');
    var table = catalogueHeader(date);
    $(docs).find('doc').each(function() {
	var name = $(this).find('name').text();
	var title = $(this).find('title').text();
	var release = $(this).find('release').text();
	var version = $(this).find('version').text();
	var html = $(this).find('html').text();
	var pdf = $(this).find('pdf').text();
	var singlehtml = $(this).find('singlehtml').text();
	var empty = '<td></a></td>\n';
	table += '<tr>\n';
	if (html)
	    table += '<td><a href="' + html + '">' + title + '</a></td>\n';
	else
	    table += empty;
	if (pdf)
	    table += '<td><a href="' + '/' + pdf + '">' +
 	    '<img src="' + pdfIcon + '" width="20" height="20"></a></td>\n';
	else
	    table += empty;
	if (singlehtml)
	    table += '<td><a href="' + '/' + singlehtml + '">' +
	    '<img src="' + htmlIcon + '" width="20" height="20"></a></td>\n';
	else
	    table += empty;
	table += '</tr>\n';
    });
    table += catalogueFooter();
    el_cat_title.html('<h3>' + $(title).text() + '</h3>');
    el_cat.html(table);
}

function loadCatalogue(path) {
    var f = $.get(path, function(xml) {
	paintCatalogue(xml);
    }, 'xml');
}