Overview
The image popup viewer (IPV) shows the full image of a thumbnail over the page. A click on any image with nds-ipv-thumbnail opens the viewer. The page holds only the thumbnails, each with an optional card and caption. The script builds the viewer: the full image, the zoom and close buttons, the arrows, a counter and a control list.
Pick another component when:
Markup
Variants
The zoom badge goes on every .nds-ipv-image-card in the markup.
| Group | Option | Markup | On element | Use |
|---|---|---|---|---|
| Zoom badge | Zoom badge | .nds-zoom-badge |
.nds-ipv-image-card |
A magnifier in the corner of the image. Add it when nothing else shows that the image opens |
Built-in Features
-
Auto-initialization
The viewer starts on any page that has an
nds-ipv-thumbnail. A thumbnail added later opens on a click with no call, andNDS.Ipv.init()lets Tab reach it. The viewer itself is built on the first open, so a page where nobody opens an image carries none of it. -
Multi-input Zoom
The mouse wheel zooms toward the pointer, and a pinch zooms toward the middle of the two fingers. The zoom buttons zoom by 1.5×. Zoom runs from 10% to 1000%, and a label shows the current value.
-
Drag to Pan
Drag the image with the mouse or one finger to move it. A double-click or the reset button returns it to 100% in the center.
-
Gallery Navigation
The arrow buttons show the image of the previous or next thumbnail on the page, and a counter shows the position. With one thumbnail on the page, the arrows and the counter are hidden.
-
Keyboard Controls
The script adds
tabindex="0"androle="button"to each thumbnail that has none. Tab reaches a thumbnail, and Enter or Space opens it. The viewer's keys are in the Keyboard table of the API. -
Distraction-free Mode
The eye button hides the other buttons, the arrows, the counter, the zoom label and the control list. The eye button stays, to bring them back.
-
Adaptive Image Loading
The page loads the small thumbnail. The viewer loads the full image from
data-ipv-fullonly when it opens, and shows a spinner until the image arrives. -
Accessible Dialog
The viewer is a modal dialog. Focus moves to its close button and stays inside the viewer. On close, focus returns to the thumbnail that opened it.
-
Localized Controls
The button labels and the control list follow the page language. The English is in the script, and the Arabic in the
ipvsection ofassets/i18n/ar.json. -
Phone Layout
On phones the buttons sit closer to the edge, and the control list is hidden.
Best Practices
- Use the viewer for images people inspect: photos, maps, plans and scans. Do not use it for decorative images.
- Put
data-ipv-fullon every thumbnail, with the URL of a large image. Without it, the viewer shows the thumbnail, which blurs when zoomed. - Keep thumbnails small, about 400px wide.
- Put
nds-imageon each.nds-ipv-image-card, so the tiles share one shape. Leave it off for your own look:nds-ipv-thumbnailadds no style. - Write
alton every thumbnail. The viewer copies it to the full image, and it names the thumbnail for screen readers. - In a gallery, put a
nds-ipv-image-titleunder each image, so people know what it shows before they open it. - For more than one gallery on a page, give each thumbnail a
data-ipv-galleryname. The arrows page through the thumbnails with the same name, in page order. Thumbnails without a name form one gallery together. - Do not add your own click handler to a thumbnail. The viewer already opens on a click, Enter and Space.
- Do not open a modal while the viewer is open. The modal opens on top of the viewer.
API
Classes
| Class | Element | Effect |
|---|---|---|
nds-ipv-thumbnail |
<img> |
Opens the viewer on a click. It does not size the image: your own styles stay as written. Required |
nds-ipv-image-card |
the thumbnail’s parent | Holds the zoom badge. With nds-image, it crops the thumbnail to one shape: see Image. Optional: a thumbnail without it works the same |
nds-zoom-badge |
.nds-ipv-image-card |
Shows a magnifier in the bottom start corner |
nds-ipv-image-title |
an element after the card | A caption under the image. Optional |
Data Attributes
| Attribute | Element | Effect |
|---|---|---|
data-ipv-full |
img.nds-ipv-thumbnail |
The URL of the image the viewer loads |
data-src |
img.nds-ipv-thumbnail |
The viewer loads this URL when the image has no data-ipv-full. With neither, it loads the image’s src |
data-ipv-gallery |
img.nds-ipv-thumbnail |
A gallery name. The arrows and the counter cover only the thumbnails with the same name |
Keyboard
| Key | Effect |
|---|---|
| Enter, Space | Opens the viewer on the focused thumbnail |
| Escape | Closes the viewer |
+ or =, - |
Zooms in or out by 1.5× |
0 |
Resets the zoom and the position |
| H | Does what the eye button does |
| Left, Right | Moves to the image on that side of the screen |
| Tab | Moves between the viewer’s buttons |
JavaScript
The NDS.Ipv script loads after the page shows. Until it loads, each call loads it and returns a promise of the result, so await a call whose result you use.
One viewer serves the whole page. The methods below drive it. The viewer fires no events.
| Method | Effect |
|---|---|
NDS.Ipv.init() |
Starts the viewer and gives thumbnails added since the last call tabindex and role. The loader calls it when the page has a thumbnail. Call it after you add thumbnails |
NDS.Ipv.open(img) |
Opens the viewer on that thumbnail |
NDS.Ipv.close() |
Closes the viewer and returns focus to the thumbnail |
NDS.Ipv.prev(), NDS.Ipv.next() |
Moves to the previous or the next thumbnail in its gallery |
NDS.Ipv.resetZoom() |
Resets the zoom and the position |
NDS.Ipv.toggleControls() |
Does what the eye button does |
NDS.Ipv.destroy() |
Removes the viewer and every listener it added. NDS.Ipv.init() starts a new one |
The full API is in the banner of _js/nds-ipv.js.