Enhance sticky-margin functionality and improve documentation#9
Enhance sticky-margin functionality and improve documentation#9Tom-van-Woudenberg merged 9 commits intomainfrom
Conversation
Fix double show, scrollbar flickering, and sidebar trigger
Expand sticky-margin to work with images, figures and other HTML elements instead of only figure images. Update docs to refer to "elements" and show new examples (use :figclass for figure directives; :class still works for div-producing directives and image directives). Refactor JavaScript: rename source/target variables to sourceFlightElement/targetFlightElement, clone arbitrary elements (not just img), derive target from aside.querySelector('figure') || aside.firstElementChild, and update visibility/animation checks accordingly. Minor docs tweaks (added admonition examples and MathJax wording) and small code cleanup around preparation/visibility handling.
Replace the simple FIGURE/closest logic with explicit branches so DIV-tagged .sticky-margin elements are treated as standalone mainFigure. For other tags, fall back to the closest <figure> or the marker itself. This enables standalone or nested div.sticky-margin blocks to be sticky on their own and avoids missing mainFigure when no enclosing <figure> exists.
Change the include start marker in MANUAL.md from the visible heading '## Installation' to an explicit HTML comment '<!-- Install start -->'. Add this comment to README.md just before the Installation section so the include can target a stable, non-visible marker instead of matching visible heading text.
Introduce a configurable sticky_margin "trigger" (full or partial) and wire it from Sphinx config into the frontend. Adds app.add_config_value("sticky_margin", ...) and a config-inited handler that validates the value, logs a warning for invalid entries, and emits a small JS snippet setting stickyMarginTrigger. Update the sticky-margin.js to read and normalize the trigger, fallback to "full" for invalid values, and change visibility logic to support the "partial" mode and avoid unnecessary evaluations. Also update README with usage and config examples (including Jupyter Book) and add a logger import and docstring tweak.
Tom-van-Woudenberg
left a comment
There was a problem hiding this comment.
Looks good!
When applying a sticky-margin to this directive, I get a horizontal scrollbar (with trigger: full) during the flying animation and I don't see the actual animation:
::::{admonition} Uitwerking
:class: solution, dropdown, sticky-margin
In de $y$-richting kan de locatie gevonden worden ten opzichte van de rechter wand:
```{figure} ./toz_data/statisch_moment.svg
:align: center
:source: https://github.com/Structural-Mechanics-CEG/mechanics-figures-source/tree/main/TOZ_schuifspanningen
:number:
```
$$\bar y_{\rm{N.C.}} = \cfrac{S_{\bar y}}{A} = \cfrac{300 \cdot 12 \cdot \cfrac{300}{2}}{300 \cdot 12 + 300 \cdot 12} = 75 \, \rm{mm}$$
::::Futhermore, the order in the sidebar is not correct anymore:
The figure on the right goes partially out of view earlier than the other figure, so it should show first in the sidebar, now when the second figure goes partially out of view it moves the other figure down.
Clarify docs and guard against conflicting classes: update MANUAL.md to use "elements" instead of "figures" for sticky margin wording; extend README.md with a caution about DOM/render order and a note that combining the `sticky-margin` and `dropdown` classes is unsupported. Add runtime protection in sticky-margin.js to remove the `sticky-margin` class and emit a console warning when an element also has `dropdown`, preventing conflicting behaviors.
Tom-van-Woudenberg
left a comment
There was a problem hiding this comment.
as the numbering of the elements is based on the DOM/node order
That's not the case. I made it such that the order is based on the order on the rendered page:
https://github.com/TeachBooks/Sphinx-Sticky-Margin/blob/main/src/sphinx_sticky_margin/assets/sticky-margin.js#L52
For 'partial' the priority of top and bottom should be swapped
Clarify ordering rules in README and update sorting logic to respect the sticky trigger mode. README now documents explicit sort orders for `full` (bottom, top, left, height, width, DOM) and `partial` (top, bottom, left, height, width, DOM). JavaScript sorting was adjusted to check `stickyTriggerMode`: in `full` mode figures are compared by bottom then top, while in `partial` mode they are compared by top then bottom (with left/height/width/DOM as fallback). Also updated an explanatory comment to reflect the different activation points.
|
I changed the README and added the swap. Can you test and review? |

Functionality added:
full("margin element appears when original element disappears above the header") or topartial("margin element appears when original element reaches the header") and corresponding disappearing behavior.