- Status changed to RTBC
almost 2 years ago 4:56pm 17 March 2023 - πΊπΈUnited States emerham
Can confirm that this does fix the issue when big pipe is on.
- π«π·France flocondetoile Lyon
if ($(context).toArray()[0].constructor.name === 'HTMLDocument')
This looks a little ugly. Why not use the library core/once to ensure backToTop element are added only once ?
- Status changed to Needs work
over 1 year ago 4:45pm 27 June 2023 - π«π·France flocondetoile Lyon
Hum you should be able to target multiple elements on the same page. And the syntax looks strange. See https://www.drupal.org/node/3158256 β
var toc_js = $(once('processBackToTop', '.toc-js', context)); toc_js.each(...);
or
var toc_js = once('processBackToTop', '.toc-js', context); toc_js.forEach(...);
- πΊπΈUnited States emerham
Rewrote to match code example.
Tested with Multiple headings on my page as well as mutliple ToC JS blocks on the same page and can confirm that every heading that was added to the ToC list gets a back to the top. On the headings of the same level in both ToC blocks I do see two links so I can confirm that this is working once for each block.
- πΊπΈUnited States emerham
I did attempt to apply the each to the back to top section
var opts = $.extend({}, nav.toc.defaults, options); if (opts.backToTop) { var scrollTo = function(e, callback) { if (opts.smoothScrolling && typeof opts.smoothScrolling === 'function') { e.preventDefault(); var elScrollTo = $(e.target).attr('href'); opts.smoothScrolling(elScrollTo, opts, callback); } $('li', self).removeClass(opts.activeClass); $(e.target).parent().addClass(opts.activeClass); }; nav.find('a').each(function () { var container = $(opts.container); var anchor = $(this).attr('href').replace(/^#/, ''); var anchorNameToTop = anchor + '-to-top'; $(this).attr('id', anchorNameToTop); var $span = container.find('span[id="' + anchor + '"]'); var anchorToTop = $('<a/>') .attr('href', '#' + anchorNameToTop) .addClass('back-to-top') .text(opts.backToTopLabel) .insertAfter($span) .bind('click', function(e) { scrollTo(e, function() { }); nav.trigger('selected', $(this).attr('href')); }); }); }
but I believe that since this is inside the .each from line 14 it got called mutliple times so the once didn't matter.
-
emerham β
authored 5f2d1ecc on 2.0.x
Issue #3334941 by emerham, el1_1el, flocondetoile: When running with...
-
emerham β
authored 5f2d1ecc on 2.0.x
- Status changed to Fixed
over 1 year ago 7:42am 7 July 2023 - π«π·France flocondetoile Lyon
Committed. Thanks. For #8 I think it's another issue. If you two block toc-js which target the same heading, then it's normal to have two back-to-top links added. If you wan't limit the number of back-to-top links added, then the question is which anchor choose to only get one back-to-top link. The easier way should be to add a class on the span targeted and then target only the span whitout this class. But it's another issue.
Automatically closed - issue fixed for 2 weeks with no activity.
- Status changed to Fixed
about 1 year ago 10:19am 3 October 2023 - π¦πΉAustria tgoeg
Is there anything open that prevents releasing this as a stable/supported version? Drupal 9 will soon reach EOL, so a stable release for D10 would be important.