dynsections.js 7.9 KB

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