| 146 | $('#foldclosed'+id).toggle(); |
| 147 | } |
| 148 | function 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+'\')">…</a>'+end); |
| 187 | // insert constructed line into closed div |
| 188 | $('#foldclosed'+id).html(line); |
| 189 | }); |
| 190 | } |
| 191 | |
| 192 | /* @license-end */ |