From: Jérémy Fabre Date: Tue, 26 Jul 2016 14:32:13 +0000 (+0200) Subject: JS Summary can now have multiple content block to scan X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=97459e2338a8ff15e872edd950a227567e720dae;p=mezzo.git JS Summary can now have multiple content block to scan --- diff --git a/app/static/src/js/modules/summary.js b/app/static/src/js/modules/summary.js index c6a1b8f2..f7fdc6c2 100644 --- a/app/static/src/js/modules/summary.js +++ b/app/static/src/js/modules/summary.js @@ -13,21 +13,26 @@ var Summary = function() { Summary.prototype.init = function() { var that = this, - $template; + $template, sectionCount = 0; - if(that.$summary.length == 1 && that.$content.length == 1) { + if(that.$summary.length == 1 && that.$content.length > 0) { $template = that.$summary.find('li:first-child'); - that.$content.find('h2').each(function(idx) { + that.$content.each(function(idx) { - var $element = $(this), - $template_clone = $template.clone(); - $template_clone.find('a').text($element.text()); - $template_clone.find('a').attr('href', '#section-' + idx); - $template_clone.removeClass('hide'); - that.$summary.append($template_clone); + $(this).find('h2').each(function(idx) { - $element.attr('id', "section-" + idx); + var $element = $(this), + $template_clone = $template.clone(); + $template_clone.find('a').text($element.text()); + $template_clone.find('a').attr('href', '#section-' + sectionCount); + $template_clone.removeClass('hide'); + that.$summary.append($template_clone); + + $element.attr('id', "section-" + sectionCount); + sectionCount++; + + }); });