dynsections.js 7.5 KB

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