MCPcopy Create free account
hub / github.com/Simsys/qhexedit2 / init_codefold

Function init_codefold

doc/html/dynsections.js:148–190  ·  view source on GitHub ↗
(relPath)

Source from the content-addressed store, hash-verified

146 $('#foldclosed'+id).toggle();
147}
148function init_codefold(relPath) {
149 $('span[class=lineno]').css(
150 {'padding-right':'4px',
151 'margin-right':'2px',
152 'display':'inline-block',
153 'width':'54px',
154 'background':'linear-gradient(var(--fold-line-color),var(--fold-line-color)) no-repeat 46px/2px 100%'
155 });
156 // add global toggle to first line
157 $('span[class=lineno]:first').append('<span class="fold" id="fold_all" '+
158 'onclick="javascript:codefold_toggle_all('+relPath+');" '+
159 'style="background-image:'+minusImg[relPath]+';"></span>');
160 // add vertical lines to other rows
161 $('span[class=lineno]').not(':eq(0)').append('<span class="fold"></span>');
162 // add toggle controls to lines with fold divs
163 $('div[class=foldopen]').each(function() {
164 // extract specific id to use
165 var id = $(this).attr('id').replace('foldopen','');
166 // extract start and end foldable fragment attributes
167 var start = $(this).attr('data-start');
168 var end = $(this).attr('data-end');
169 // replace normal fold span with controls for the first line of a foldable fragment
170 $(this).find('span[class=fold]:first').replaceWith('<span class="fold" '+
171 'onclick="javascript:codefold_toggle(\''+id+'\');" '+
172 'style="background-image:'+minusImg[relPath]+';"></span>');
173 // append div for folded (closed) representation
174 $(this).after('<div id="foldclosed'+id+'" class="foldclosed" style="display:none;"></div>');
175 // extract the first line from the "open" section to represent closed content
176 var line = $(this).children().first().clone();
177 // remove any glow that might still be active on the original line
178 $(line).removeClass('glow');
179 if (start) {
180 // if line already ends with a start marker (e.g. trailing {), remove it
181 $(line).html($(line).html().replace(new RegExp('\\s*'+start+'\\s*$','g'),''));
182 }
183 // replace minus with plus symbol
184 $(line).find('span[class=fold]').css('background-image',plusImg[relPath]);
185 // append ellipsis
186 $(line).append(' '+start+'<a href="javascript:codefold_toggle(\''+id+'\')">&#8230;</a>'+end);
187 // insert constructed line into closed div
188 $('#foldclosed'+id).html(line);
189 });
190}
191
192/* @license-end */

Callers

nothing calls this directly

Calls 2

$Function · 0.85
replaceMethod · 0.80

Tested by

no test coverage detected