Closed (fixed)
Project:
BS Lib
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
24 Apr 2020 at 21:18 UTC
Updated:
30 Jun 2021 at 18:09 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
pivica commentedHere is a first patch. More testing is needed including IE11 and Safari.
Comment #3
pivica commentedAdded focus element on scroll and skipping of links with just a # sign.
Comment #4
pivica commentedNeed to reorder scrollTo and focus calls. Commented initial 50px scroll hack for now. Some minor refactoring.
Comment #5
pivica commentedAdded exclude_elements options, this also eliminated a need for custom 50px initial scroll hack :)
Added settings form.
Various refactorings.
Quite flexible now with supported options, hopefully, it can be adapted for most use cases.
This should be ready for real tests now.
Comment #6
pivica commentedComment #7
pivica commentedComment #8
pivica commentedComment #9
pivica commentedComment #10
pivica commentedNew patch, couple of bigger changes:
Tested this on a couple of browsers:
Comment #11
berdirFor the list-like settings, why not store it as a list on config? Then the update function and initialization logic could work with a PHP array and you don't have to implode it again on form submit. Just set type: sequence and then nested type string in the config schema, something like this:
Comment #12
pivica commented> For the list-like settings, why not store it as a list on config?
Yeah, i forgot that one, good idea. Implemented.
Also added menu link definition.
Comment #13
pivica commentedFixed schema indentation.
Comment #14
pivica commentedMessed up indentation fix in previous patch, this one should be good.
Comment #15
pivica commentedNew patch is doing next things:
- More accurate calculation of fixed elements offset. Now we can consider overlapped fixed elements.
- Adding triggering of custom events bslib.anchorscroll.fastrscrollended and bslib.anchorscroll.smoothscrollended.
- Expose API window.BSLib.getFixedElementsOffset() method.
Last two we needed for some custom TOC functionality.
Comment #16
pivica commentedIdea of two phase scrolling (fast and then smooth) is nice but I can imagine that not everybody will like it. We should introduce option for this so people can choose. The option can be named type and it can have 3 values:
- smooth
- fast
- fast then smooth (this is current default behavior)
Option 'smooth' means the whole scrolling is done smooth.
Option 'fast' means the whole scrolling is done fast (jump). This is the same as default browser anchor scroll behavior, except we are doing all calculations for fixed elements, etc.
We can default this new option to 'fast then smooth' or 'smooth'.
Comment #17
mbovan commentedAdded a check to exclude the library in the admin theme.
I am leaving the issue status to "Needs work" as per #16.
Comment #18
berdirwhy not use \Drupal::service('router.admin_context')->isAdminRoute(), that's much easier. and in theory sites don't need to have a different backend and frontend theme.
Comment #19
mbovan commentedAs discussed, I've had issues with
\Drupal::service('router.admin_context')->isAdminRoute()returningFALSEon admin ajax requests and that was the reasoning for #17.Since
hook_page_attachments()is not invoked on ajax requests, updated the fix to use\Drupal::service('router.admin_context')->isAdminRoute()instead.Comment #20
pivica commentedNew patch is fixing some edge cases in getFixedElementsOffset() method, renames some functions and improve comments.
Comment #21
pivica commented> We should introduce option for this so people can choose. The option can be named type and it can have 3 values
Tried to do this but it is not that easy, discovered some additional problems, moving this to #3167782: Scroll behaviors option.
Comment #22
pivica commentedWe should check for empty fixed selectors because they produce bugs in the code.
Comment #24
pivica commentedMerged finally, thank you all for your help.