dynsections.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. let dynsection = {
  20. // helper function
  21. updateStripes : function() {
  22. $('table.directory tr').
  23. removeClass('even').filter(':visible:even').addClass('even');
  24. $('table.directory tr').
  25. removeClass('odd').filter(':visible:odd').addClass('odd');
  26. },
  27. toggleVisibility : function(linkObj) {
  28. const base = $(linkObj).attr('id');
  29. const summary = $('#'+base+'-summary');
  30. const content = $('#'+base+'-content');
  31. const trigger = $('#'+base+'-trigger');
  32. const src=$(trigger).attr('src');
  33. if (content.is(':visible')===true) {
  34. content.hide();
  35. summary.show();
  36. $(linkObj).addClass('closed').removeClass('opened');
  37. $(trigger).attr('src',src.substring(0,src.length-8)+'closed.png');
  38. } else {
  39. content.show();
  40. summary.hide();
  41. $(linkObj).removeClass('closed').addClass('opened');
  42. $(trigger).attr('src',src.substring(0,src.length-10)+'open.png');
  43. }
  44. return false;
  45. },
  46. toggleLevel : function(level) {
  47. $('table.directory tr').each(function() {
  48. const l = this.id.split('_').length-1;
  49. const i = $('#img'+this.id.substring(3));
  50. const a = $('#arr'+this.id.substring(3));
  51. if (l<level+1) {
  52. i.removeClass('iconfopen iconfclosed').addClass('iconfopen');
  53. a.html('&#9660;');
  54. $(this).show();
  55. } else if (l==level+1) {
  56. i.removeClass('iconfclosed iconfopen').addClass('iconfclosed');
  57. a.html('&#9658;');
  58. $(this).show();
  59. } else {
  60. $(this).hide();
  61. }
  62. });
  63. this.updateStripes();
  64. },
  65. toggleFolder : function(id) {
  66. // the clicked row
  67. const currentRow = $('#row_'+id);
  68. // all rows after the clicked row
  69. const rows = currentRow.nextAll("tr");
  70. const re = new RegExp('^row_'+id+'\\d+_$', "i"); //only one sub
  71. // only match elements AFTER this one (can't hide elements before)
  72. const childRows = rows.filter(function() { return this.id.match(re); });
  73. // first row is visible we are HIDING
  74. if (childRows.filter(':first').is(':visible')===true) {
  75. // replace down arrow by right arrow for current row
  76. const currentRowSpans = currentRow.find("span");
  77. currentRowSpans.filter(".iconfopen").removeClass("iconfopen").addClass("iconfclosed");
  78. currentRowSpans.filter(".arrow").html('&#9658;');
  79. rows.filter("[id^=row_"+id+"]").hide(); // hide all children
  80. } else { // we are SHOWING
  81. // replace right arrow by down arrow for current row
  82. const currentRowSpans = currentRow.find("span");
  83. currentRowSpans.filter(".iconfclosed").removeClass("iconfclosed").addClass("iconfopen");
  84. currentRowSpans.filter(".arrow").html('&#9660;');
  85. // replace down arrows by right arrows for child rows
  86. const childRowsSpans = childRows.find("span");
  87. childRowsSpans.filter(".iconfopen").removeClass("iconfopen").addClass("iconfclosed");
  88. childRowsSpans.filter(".arrow").html('&#9658;');
  89. childRows.show(); //show all children
  90. }
  91. this.updateStripes();
  92. },
  93. toggleInherit : function(id) {
  94. const rows = $('tr.inherit.'+id);
  95. const img = $('tr.inherit_header.'+id+' img');
  96. const src = $(img).attr('src');
  97. if (rows.filter(':first').is(':visible')===true) {
  98. rows.css('display','none');
  99. $(img).attr('src',src.substring(0,src.length-8)+'closed.png');
  100. } else {
  101. rows.css('display','table-row'); // using show() causes jump in firefox
  102. $(img).attr('src',src.substring(0,src.length-10)+'open.png');
  103. }
  104. },
  105. };
  106. let codefold = {
  107. opened : true,
  108. // in case HTML_COLORSTYLE is LIGHT or DARK the vars will be replaced, so we write them out explicitly and use double quotes
  109. plusImg: [ "var(--fold-plus-image)", "var(--fold-plus-image-relpath)" ],
  110. minusImg: [ "var(--fold-minus-image)", "var(--fold-minus-image-relpath)" ],
  111. // toggle all folding blocks
  112. toggle_all : function(relPath) {
  113. if (this.opened) {
  114. $('#fold_all').css('background-image',this.plusImg[relPath]);
  115. $('div[id^=foldopen]').hide();
  116. $('div[id^=foldclosed]').show();
  117. } else {
  118. $('#fold_all').css('background-image',this.minusImg[relPath]);
  119. $('div[id^=foldopen]').show();
  120. $('div[id^=foldclosed]').hide();
  121. }
  122. this.opened=!this.opened;
  123. },
  124. // toggle single folding block
  125. toggle : function(id) {
  126. $('#foldopen'+id).toggle();
  127. $('#foldclosed'+id).toggle();
  128. },
  129. init : function(relPath) {
  130. $('span[class=lineno]').css({
  131. 'padding-right':'4px',
  132. 'margin-right':'2px',
  133. 'display':'inline-block',
  134. 'width':'54px',
  135. 'background':'linear-gradient(var(--fold-line-color),var(--fold-line-color)) no-repeat 46px/2px 100%'
  136. });
  137. // add global toggle to first line
  138. $('span[class=lineno]:first').append('<span class="fold" id="fold_all" '+
  139. 'onclick="javascript:codefold.toggle_all('+relPath+');" '+
  140. 'style="background-image:'+this.minusImg[relPath]+';"></span>');
  141. // add vertical lines to other rows
  142. $('span[class=lineno]').not(':eq(0)').append('<span class="fold"></span>');
  143. // add toggle controls to lines with fold divs
  144. $('div[class=foldopen]').each(function() {
  145. // extract specific id to use
  146. const id = $(this).attr('id').replace('foldopen','');
  147. // extract start and end foldable fragment attributes
  148. const start = $(this).attr('data-start');
  149. const end = $(this).attr('data-end');
  150. // replace normal fold span with controls for the first line of a foldable fragment
  151. $(this).find('span[class=fold]:first').replaceWith('<span class="fold" '+
  152. 'onclick="javascript:codefold.toggle(\''+id+'\');" '+
  153. 'style="background-image:'+codefold.minusImg[relPath]+';"></span>');
  154. // append div for folded (closed) representation
  155. $(this).after('<div id="foldclosed'+id+'" class="foldclosed" style="display:none;"></div>');
  156. // extract the first line from the "open" section to represent closed content
  157. const line = $(this).children().first().clone();
  158. // remove any glow that might still be active on the original line
  159. $(line).removeClass('glow');
  160. if (start) {
  161. // if line already ends with a start marker (e.g. trailing {), remove it
  162. $(line).html($(line).html().replace(new RegExp('\\s*'+start+'\\s*$','g'),''));
  163. }
  164. // replace minus with plus symbol
  165. $(line).find('span[class=fold]').css('background-image',codefold.plusImg[relPath]);
  166. // append ellipsis
  167. $(line).append(' '+start+'<a href="javascript:codefold.toggle(\''+id+'\')">&#8230;</a>'+end);
  168. // insert constructed line into closed div
  169. $('#foldclosed'+id).html(line);
  170. });
  171. },
  172. };
  173. /* @license-end */