From 97459e2338a8ff15e872edd950a227567e720dae Mon Sep 17 00:00:00 2001 From: =?utf8?q?Je=CC=81re=CC=81my=20Fabre?= Date: Tue, 26 Jul 2016 16:32:13 +0200 Subject: [PATCH] JS Summary can now have multiple content block to scan --- app/static/src/js/modules/summary.js | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) 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++; + + }); }); -- 2.39.5