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