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