summaryrefslogtreecommitdiff
path: root/docs/docs.rtems.org/static/rtems/js/catalogue.js
blob: 37b1e51365f3efac4868b51eeed5aec4b9024ecf (plain)
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*!
 * Catalogue 0.1
 * Copyright 2017 Chris Johns <chrisj@rtems.org>
 * Licensed under the MIT license
 */

function catalogueHeader(id, title, date) {
    return '' +
	' <div class="table-responsive">' +
        '  <table class="table table-hover table-condensed table-nonfluid">' +
	'   <tbody>' +
	'    <thead>' +
	'     <tr id="' + id + '" class="accordion-toggle" data-toggle="collapse"' +
	'         data-parent="#rtems-catalogue" data-target=".' + id + 'Details">' +
	'      <th class="col-sm-2"><span class="label label-default pull-right">' + date + '</span></th>\n' +
	'      <th class="col-sm-2"><span>' + title + '</span></th>\n' +
	'      <th width="30px"><i class="indicator glyphicon glyphicon-chevron-up pull-right"></i></th>' +
	'     </tr>' +
	'    </thead>' +
	'    <tr>' +
	'     <td colspan="3" class="hiddenRow">' +
	'      <div class="accordion-body collapse ' + id + 'Details" id="' + id + '1">' +
	'       <table class="table table-hoover table-condensed table-nonfluid">' +
	'        <tbody>' +
	'         <thead><tr><th>Online</th><th>PDF</th><th>Single Page</th></tr></thead>';
}

function catalogueFooter() {
    return '' +
	'        </tbody>' +
	'       </table>' +
	'      </div>' +
	'     </td>' +
	'    </tr>' +
        '   </tbody>' +
	'  </table>' +
	' </div/>';
}



function panel_handlers(tag, id, show) {
    $('#' + id + '1').on('shown.bs.collapse', function () {
	$("#" + id + " i.indicator").removeClass("glyphicon-chevron-up").addClass("glyphicon-chevron-down");
	var top = $('#rtems-catalogue-' + tag).offset().top;
	$('html, body').animate({ scrollTop: top }, 500);
    });
    $('#' + id + '1').on('hidden.bs.collapse', function () {
	$("#" + id + " i.indicator").removeClass("glyphicon-chevron-down").addClass("glyphicon-chevron-up");
    });
    if (show == true)
	$('#' + id + '1').collapse('show');
}

function paintCatalogue(xml, path, tag, doxygen, show) {
    var el_cat = $('#rtems-catalogue-' + tag);
    if (path.slice(-1) != '/')
	path = path + '/';
    /*
     * Use jquery as XMLDocument is consider not stable on Firefox's web site.
     */
    var pdfIcon = 'static/img/Adobe_PDF_file_icon_32x32.png';
    var htmlIcon = 'static/img/html-xxl.png';
    var docs = $(xml).find('rtems-docs');
    var date = $(docs).attr('date');
    var title = $(docs).find('catalogue');
    var id = title.text().replace(/\.| |\(|\)|\[|\]/g, '_');
    var table = catalogueHeader(id, title.text(), date);
    var empty = '<td></a></td>\n';
    $(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();
	table += '<tr>\n';
	if (html)
	    table += '<td><a href="' + path + html + '">' + title + '</a></td>\n';
	else
	    table += empty;
	if (pdf)
	    table += '<td><a href="' + path + pdf + '">' +
 	    '<img src="' + pdfIcon + '" width="20" height="20"></a></td>\n';
	else
	    table += empty;
	if (singlehtml)
	    table += '<td><a href="' + path + singlehtml + '">' +
	    '<img src="' + htmlIcon + '" width="20" height="20"></a></td>\n';
	else
	    table += empty;
	table += '</tr>\n';
    });
    if (doxygen == true) {
	table += '<tr>\n';
	table += '<td><a href="doxygen/' + path.replace('docs', 'doxygen') + '">RTEMS CPU Kit Doxygen</a></td>\n';
	table += empty;
	table += empty;
	table += '</tr>\n';
    }
    table += catalogueFooter();
    el_cat.html(table);
    panel_handlers(tag, id, show);
}

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