github.com/darmach/terratest@v0.34.8-0.20210517103231-80931f95e3ff/docs/assets/js/collection-browser_toc.js (about) 1 $(document).ready(function () { 2 $('#toc-toggle-open').on('click', function () { 3 $('.col-md-2-5').addClass('opened') 4 $('body').addClass('modal-opened') 5 }) 6 7 $('#toc-toggle-close').on('click', function () { 8 $('.col-md-2-5').removeClass('opened') 9 $('body').removeClass('modal-opened') 10 }) 11 12 $('#toc a').on('click', function (){ 13 $('.col-md-2-5').removeClass('opened') 14 $('body').removeClass('modal-opened') 15 }) 16 17 /* Collapsing toc */ 18 $('#toc ul ul').addClass('collapse') 19 20 // Change initial icon for nav without children: 21 $('#toc .nav-collapse-handler').each(function () { 22 if ($(this).siblings('ul').length === 0) { 23 $(this).find('.glyphicon').removeClass('glyphicon-triangle-bottom') 24 $(this).find('.glyphicon').addClass('glyphicon-chevron-down') 25 $(this).addClass('no-children') 26 } 27 }) 28 29 // Expand / collpase on click 30 $('#toc .nav-collapse-handler').on('click', function() { 31 toggleNav($(this)) 32 }) 33 34 $(docSidebarInitialExpand) 35 }) 36 37 // Expand / collpase on click 38 function toggleNav(el) { 39 if (el.hasClass('collapsed')) { 40 if (!el.hasClass('no-children')) { 41 el.removeClass('collapsed') 42 el.siblings('ul').collapse('show') 43 } 44 } else { 45 el.addClass('collapsed') 46 el.siblings('ul').collapse('hide') 47 } 48 } 49 50 const docSidebarInitialExpand = function () { 51 const toc = $('#toc') 52 const pathname = window.location.pathname 53 const hash = window.location.hash 54 toc.find('a[href="'+pathname+hash+'"]').each(function(i, nav) { 55 $(nav).parents('ul').each(function(i, el) { 56 $(el).collapse('show') 57 $(el).siblings('span.nav-collapse-handler:not(.no-children)').removeClass('collapsed') 58 $(el).siblings('span.nav-collapse-handler').addClass('active') 59 }) 60 $(nav).siblings('span.nav-collapse-handler:not(.no-children)').removeClass('collapsed') 61 $(nav).siblings('span.nav-collapse-handler').addClass('active') 62 $(nav).siblings('ul').collapse('show') 63 }) 64 }