]> begriffs open source - cmsis-freertos/blob - main/dynsections.js
Update documentation for branch main
[cmsis-freertos] / main / dynsections.js
1 /*
2  @licstart  The following is the entire license notice for the JavaScript code in this file.
3
4  The MIT License (MIT)
5
6  Copyright (C) 1997-2020 by Dimitri van Heesch
7
8  Permission is hereby granted, free of charge, to any person obtaining a copy of this software
9  and associated documentation files (the "Software"), to deal in the Software without restriction,
10  including without limitation the rights to use, copy, modify, merge, publish, distribute,
11  sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
12  furnished to do so, subject to the following conditions:
13
14  The above copyright notice and this permission notice shall be included in all copies or
15  substantial portions of the Software.
16
17  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
18  BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
23  @licend  The above is the entire license notice for the JavaScript code in this file
24  */
25
26 function toggleVisibility(linkObj) {
27   return dynsection.toggleVisibility(linkObj);
28 }
29
30 let dynsection = {
31
32   // helper function
33   updateStripes : function() {
34     $('table.directory tr').
35       removeClass('even').filter(':visible:even').addClass('even');
36     $('table.directory tr').
37       removeClass('odd').filter(':visible:odd').addClass('odd');
38   },
39
40   toggleVisibility : function(linkObj) {
41     const base = $(linkObj).attr('id');
42     const summary = $('#'+base+'-summary');
43     const content = $('#'+base+'-content');
44     const trigger = $('#'+base+'-trigger');
45     const src=$(trigger).attr('src');
46     if (content.is(':visible')===true) {
47       content.hide();
48       summary.show();
49       $(linkObj).addClass('closed').removeClass('opened');
50       $(trigger).attr('src',src.substring(0,src.length-8)+'closed.png');
51     } else {
52       content.show();
53       summary.hide();
54       $(linkObj).removeClass('closed').addClass('opened');
55       $(trigger).attr('src',src.substring(0,src.length-10)+'open.png');
56     }
57     return false;
58   },
59
60   toggleLevel : function(level) {
61     $('table.directory tr').each(function() {
62       const l = this.id.split('_').length-1;
63       const i = $('#img'+this.id.substring(3));
64       const a = $('#arr'+this.id.substring(3));
65       if (l<level+1) {
66         i.removeClass('iconfopen iconfclosed').addClass('iconfopen');
67         a.html('&#9660;');
68         $(this).show();
69       } else if (l==level+1) {
70         i.removeClass('iconfclosed iconfopen').addClass('iconfclosed');
71         a.html('&#9658;');
72         $(this).show();
73       } else {
74         $(this).hide();
75       }
76     });
77     this.updateStripes();
78   },
79
80   toggleFolder : function(id) {
81     // the clicked row
82     const currentRow = $('#row_'+id);
83
84     // all rows after the clicked row
85     const rows = currentRow.nextAll("tr");
86
87     const re = new RegExp('^row_'+id+'\\d+_$', "i"); //only one sub
88
89     // only match elements AFTER this one (can't hide elements before)
90     const childRows = rows.filter(function() { return this.id.match(re); });
91
92     // first row is visible we are HIDING
93     if (childRows.filter(':first').is(':visible')===true) {
94       // replace down arrow by right arrow for current row
95       const currentRowSpans = currentRow.find("span");
96       currentRowSpans.filter(".iconfopen").removeClass("iconfopen").addClass("iconfclosed");
97       currentRowSpans.filter(".arrow").html('&#9658;');
98       rows.filter("[id^=row_"+id+"]").hide(); // hide all children
99     } else { // we are SHOWING
100       // replace right arrow by down arrow for current row
101       const currentRowSpans = currentRow.find("span");
102       currentRowSpans.filter(".iconfclosed").removeClass("iconfclosed").addClass("iconfopen");
103       currentRowSpans.filter(".arrow").html('&#9660;');
104       // replace down arrows by right arrows for child rows
105       const childRowsSpans = childRows.find("span");
106       childRowsSpans.filter(".iconfopen").removeClass("iconfopen").addClass("iconfclosed");
107       childRowsSpans.filter(".arrow").html('&#9658;');
108       childRows.show(); //show all children
109     }
110     this.updateStripes();
111   },
112
113   toggleInherit : function(id) {
114     const rows = $('tr.inherit.'+id);
115     const img = $('tr.inherit_header.'+id+' img');
116     const src = $(img).attr('src');
117     if (rows.filter(':first').is(':visible')===true) {
118       rows.css('display','none');
119       $(img).attr('src',src.substring(0,src.length-8)+'closed.png');
120     } else {
121       rows.css('display','table-row'); // using show() causes jump in firefox
122       $(img).attr('src',src.substring(0,src.length-10)+'open.png');
123     }
124   },
125 };
126
127 let codefold = {
128   opened : true,
129
130   // in case HTML_COLORSTYLE is LIGHT or DARK the vars will be replaced, so we write them out explicitly and use double quotes
131   plusImg:  [ "var(--fold-plus-image)",  "var(--fold-plus-image-relpath)" ],
132   minusImg: [ "var(--fold-minus-image)", "var(--fold-minus-image-relpath)" ],
133
134   // toggle all folding blocks
135   toggle_all : function(relPath) {
136     if (this.opened) {
137       $('#fold_all').css('background-image',this.plusImg[relPath]);
138       $('div[id^=foldopen]').hide();
139       $('div[id^=foldclosed]').show();
140     } else {
141       $('#fold_all').css('background-image',this.minusImg[relPath]);
142       $('div[id^=foldopen]').show();
143       $('div[id^=foldclosed]').hide();
144     }
145     this.opened=!this.opened;
146   },
147
148   // toggle single folding block
149   toggle : function(id) {
150     $('#foldopen'+id).toggle();
151     $('#foldclosed'+id).toggle();
152   },
153
154   init : function(relPath) {
155     $('span[class=lineno]').css({
156       'padding-right':'4px',
157       'margin-right':'2px',
158       'display':'inline-block',
159       'width':'54px',
160       'background':'linear-gradient(var(--fold-line-color),var(--fold-line-color)) no-repeat 46px/2px 100%'
161     });
162     // add global toggle to first line
163     $('span[class=lineno]:first').append('<span class="fold" id="fold_all" '+
164       'onclick="javascript:codefold.toggle_all('+relPath+');" '+
165       'style="background-image:'+this.minusImg[relPath]+';"></span>');
166     // add vertical lines to other rows
167     $('span[class=lineno]').not(':eq(0)').append('<span class="fold"></span>');
168     // add toggle controls to lines with fold divs
169     $('div[class=foldopen]').each(function() {
170       // extract specific id to use
171       const id    = $(this).attr('id').replace('foldopen','');
172       // extract start and end foldable fragment attributes
173       const start = $(this).attr('data-start');
174       const end   = $(this).attr('data-end');
175       // replace normal fold span with controls for the first line of a foldable fragment
176       $(this).find('span[class=fold]:first').replaceWith('<span class="fold" '+
177                    'onclick="javascript:codefold.toggle(\''+id+'\');" '+
178                    'style="background-image:'+codefold.minusImg[relPath]+';"></span>');
179       // append div for folded (closed) representation
180       $(this).after('<div id="foldclosed'+id+'" class="foldclosed" style="display:none;"></div>');
181       // extract the first line from the "open" section to represent closed content
182       const line = $(this).children().first().clone();
183       // remove any glow that might still be active on the original line
184       $(line).removeClass('glow');
185       if (start) {
186         // if line already ends with a start marker (e.g. trailing {), remove it
187         $(line).html($(line).html().replace(new RegExp('\\s*'+start+'\\s*$','g'),''));
188       }
189       // replace minus with plus symbol
190       $(line).find('span[class=fold]').css('background-image',codefold.plusImg[relPath]);
191       // append ellipsis
192       $(line).append(' '+start+'<a href="javascript:codefold.toggle(\''+id+'\')">&#8230;</a>'+end);
193       // insert constructed line into closed div
194       $('#foldclosed'+id).html(line);
195     });
196   },
197 };
198 /* @license-end */