NBash

Форк
0
194 строки · 7.8 Кб
1
/*
2
 @licstart  The following is the entire license notice for the JavaScript code in this file.
3

4
 The MIT License (MIT)
5

6
 Copyright (C) 1997-2020 by Dimitri van Heesch
7

8
 Permission is hereby granted, free of charge, to any person obtaining a copy of this software
9
 and associated documentation files (the "Software"), to deal in the Software without restriction,
10
 including without limitation the rights to use, copy, modify, merge, publish, distribute,
11
 sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
12
 furnished to do so, subject to the following conditions:
13

14
 The above copyright notice and this permission notice shall be included in all copies or
15
 substantial portions of the Software.
16

17
 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
18
 BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20
 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
 OUT 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

26
let dynsection = {
27

28
  // helper function
29
  updateStripes : function() {
30
    $('table.directory tr').
31
      removeClass('even').filter(':visible:even').addClass('even');
32
    $('table.directory tr').
33
      removeClass('odd').filter(':visible:odd').addClass('odd');
34
  },
35

36
  toggleVisibility : function(linkObj) {
37
    const base = $(linkObj).attr('id');
38
    const summary = $('#'+base+'-summary');
39
    const content = $('#'+base+'-content');
40
    const trigger = $('#'+base+'-trigger');
41
    const src=$(trigger).attr('src');
42
    if (content.is(':visible')===true) {
43
      content.hide();
44
      summary.show();
45
      $(linkObj).addClass('closed').removeClass('opened');
46
      $(trigger).attr('src',src.substring(0,src.length-8)+'closed.png');
47
    } else {
48
      content.show();
49
      summary.hide();
50
      $(linkObj).removeClass('closed').addClass('opened');
51
      $(trigger).attr('src',src.substring(0,src.length-10)+'open.png');
52
    }
53
    return false;
54
  },
55

56
  toggleLevel : function(level) {
57
    $('table.directory tr').each(function() {
58
      const l = this.id.split('_').length-1;
59
      const i = $('#img'+this.id.substring(3));
60
      const a = $('#arr'+this.id.substring(3));
61
      if (l<level+1) {
62
        i.removeClass('iconfopen iconfclosed').addClass('iconfopen');
63
        a.html('&#9660;');
64
        $(this).show();
65
      } else if (l==level+1) {
66
        i.removeClass('iconfclosed iconfopen').addClass('iconfclosed');
67
        a.html('&#9658;');
68
        $(this).show();
69
      } else {
70
        $(this).hide();
71
      }
72
    });
73
    this.updateStripes();
74
  },
75

76
  toggleFolder : function(id) {
77
    // the clicked row
78
    const currentRow = $('#row_'+id);
79

80
    // all rows after the clicked row
81
    const rows = currentRow.nextAll("tr");
82

83
    const re = new RegExp('^row_'+id+'\\d+_$', "i"); //only one sub
84

85
    // only match elements AFTER this one (can't hide elements before)
86
    const childRows = rows.filter(function() { return this.id.match(re); });
87

88
    // first row is visible we are HIDING
89
    if (childRows.filter(':first').is(':visible')===true) {
90
      // replace down arrow by right arrow for current row
91
      const currentRowSpans = currentRow.find("span");
92
      currentRowSpans.filter(".iconfopen").removeClass("iconfopen").addClass("iconfclosed");
93
      currentRowSpans.filter(".arrow").html('&#9658;');
94
      rows.filter("[id^=row_"+id+"]").hide(); // hide all children
95
    } else { // we are SHOWING
96
      // replace right arrow by down arrow for current row
97
      const currentRowSpans = currentRow.find("span");
98
      currentRowSpans.filter(".iconfclosed").removeClass("iconfclosed").addClass("iconfopen");
99
      currentRowSpans.filter(".arrow").html('&#9660;');
100
      // replace down arrows by right arrows for child rows
101
      const childRowsSpans = childRows.find("span");
102
      childRowsSpans.filter(".iconfopen").removeClass("iconfopen").addClass("iconfclosed");
103
      childRowsSpans.filter(".arrow").html('&#9658;');
104
      childRows.show(); //show all children
105
    }
106
    this.updateStripes();
107
  },
108

109
  toggleInherit : function(id) {
110
    const rows = $('tr.inherit.'+id);
111
    const img = $('tr.inherit_header.'+id+' img');
112
    const src = $(img).attr('src');
113
    if (rows.filter(':first').is(':visible')===true) {
114
      rows.css('display','none');
115
      $(img).attr('src',src.substring(0,src.length-8)+'closed.png');
116
    } else {
117
      rows.css('display','table-row'); // using show() causes jump in firefox
118
      $(img).attr('src',src.substring(0,src.length-10)+'open.png');
119
    }
120
  },
121
};
122

123
let codefold = {
124
  opened : 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 quotes
127
  plusImg:  [ "url('plus.svg')",  "url('../../plus.svg')" ],
128
  minusImg: [ "url('minus.svg')", "url('../../minus.svg')" ],
129

130
  // toggle all folding blocks
131
  toggle_all : function(relPath) {
132
    if (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
    }
141
    this.opened=!this.opened;
142
  },
143

144
  // toggle single folding block
145
  toggle : function(id) {
146
    $('#foldopen'+id).toggle();
147
    $('#foldclosed'+id).toggle();
148
  },
149

150
  init : 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 line
159
    $('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 rows
163
    $('span[class=lineno]').not(':eq(0)').append('<span class="fold"></span>');
164
    // add toggle controls to lines with fold divs
165
    $('div[class=foldopen]').each(function() {
166
      // extract specific id to use
167
      const id    = $(this).attr('id').replace('foldopen','');
168
      // extract start and end foldable fragment attributes
169
      const start = $(this).attr('data-start');
170
      const end   = $(this).attr('data-end');
171
      // replace normal fold span with controls for the first line of a foldable fragment
172
      $(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) representation
176
      $(this).after('<div id="foldclosed'+id+'" class="foldclosed" style="display:none;"></div>');
177
      // extract the first line from the "open" section to represent closed content
178
      const line = $(this).children().first().clone();
179
      // remove any glow that might still be active on the original line
180
      $(line).removeClass('glow');
181
      if (start) {
182
        // if line already ends with a start marker (e.g. trailing {), remove it
183
        $(line).html($(line).html().replace(new RegExp('\\s*'+start+'\\s*$','g'),''));
184
      }
185
      // replace minus with plus symbol
186
      $(line).find('span[class=fold]').css('background-image',codefold.plusImg[relPath]);
187
      // append ellipsis
188
      $(line).append(' '+start+'<a href="javascript:codefold.toggle(\''+id+'\')">&#8230;</a>'+end);
189
      // insert constructed line into closed div
190
      $('#foldclosed'+id).html(line);
191
    });
192
  },
193
};
194
/* @license-end */
195

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.