test
1window.initializeCodeFolding = function(show) {23// handlers for show-all and hide all4$("#rmd-show-all-code").click(function() {5$('div.r-code-collapse').each(function() {6$(this).collapse('show');7});8});9$("#rmd-hide-all-code").click(function() {10$('div.r-code-collapse').each(function() {11$(this).collapse('hide');12});13});1415// index for unique code element ids16var currentIndex = 1;1718// select all R code blocks19var rCodeBlocks = $('pre.r, pre.python, pre.bash, pre.sql, pre.cpp, pre.stan');20rCodeBlocks.each(function() {2122// create a collapsable div to wrap the code in23var div = $('<div class="collapse r-code-collapse"></div>');24if (show)25div.addClass('in');26var id = 'rcode-643E0F36' + currentIndex++;27div.attr('id', id);28$(this).before(div);29$(this).detach().appendTo(div);3031// add a show code button right above32var showCodeText = $('<span>' + (show ? 'Hide' : 'Code') + '</span>');33var showCodeButton = $('<button type="button" class="btn btn-default btn-xs code-folding-btn pull-right"></button>');34showCodeButton.append(showCodeText);35showCodeButton36.attr('data-toggle', 'collapse')37.attr('data-target', '#' + id)38.attr('aria-expanded', show)39.attr('aria-controls', id);4041var buttonRow = $('<div class="row"></div>');42var buttonCol = $('<div class="col-md-12"></div>');4344buttonCol.append(showCodeButton);45buttonRow.append(buttonCol);4647div.before(buttonRow);4849// update state of button on show/hide50div.on('hidden.bs.collapse', function () {51showCodeText.text('Code');52});53div.on('show.bs.collapse', function () {54showCodeText.text('Hide');55});56});5758}596061