xGallery organizes images into evenly aligned rows. Each row has the same height, but the images within each row can have different widths. This layout style (masonry) is similar to what you see on photo sites like Flickr or Google Photos.
The photos you take are usually a mix of landscape and portrait orientations. A simple grid would have to crop them or leave gaps. J1 xGallery solves this by keeping each image in its original shape and adjusting the widths so every row fills the page neatly.
Creator Instance
A creator instance of xGallery lets you create, load, and edit galleries with all available features. Usually, you set up only one xGallery creator (read-write instance) per website to handle playlist management.
The Creator starts out empty. Everything you add appears in the browser and stays there using the browser’s localStorage, not in the site’s YAML files. This makes it a good place to try out the module without changing any files.
| Viewer instances In contrast, all other xGallery instances are set up as read-only viewers. They can play gallery sources but cannot make any changes. |
Setup Guide
This section is a compact reference of all settings a J1 gallery can have. It follows the defaults file _data/modules/defaults/gallery.yml, where every key is documented in detail. Use it to look up a key after you have read the setup guide above. The tables show the J1 default of each key, that is the value a gallery gets when you do not set the key yourself.
The three files and how they are merged
A gallery is described in the defaults file and in two files of your site. The two site files use the same list structure. Every entry starts with - gallery:, and the id is the key that joins the entries of the two files:
settings:
galleries:
- gallery:
id: <unique id>
...When the site is built, the settings of one gallery are put together from four layers. A later layer wins over an earlier one, but only for the keys it states; keys it does not state fall through from the layer above. This is called a deep merge:
| # | Layer | File |
|---|---|---|
1 | Defaults |
|
2 | Global settings |
|
3 | Gallery settings |
|
4 | Media content |
|
A few rules follow from this:
-
Write only what is different. A value that is the same as the default is not written in
gallery_control.yml; it is inherited. The shipped file marks the kind of every value with a short trailing comment:Marker Meaning # override (default: x)The value is different from the default
x.# net-newThe key does not exist in the defaults file.
# restated (default: x)The value is the same as the default; it is written only to make the entry easier to read.
# opt-inThe key switches on a feature that is off by default.
-
A partial block is safe. You can write a block like
managewith only one or two keys; the rest is taken from the defaults. A merge can only add or replace a value, it can never remove one. (This is why some keys have a value with a "remove" meaning, for examplevideoAttributes.muted: false, see PhotoSwipe settings.) -
Lists are replaced as a whole. A list in your file (for example
storage.addClassesorsortOptions) replaces the list of the defaults; the two lists are not joined. -
Only the control file switches a gallery on. The
enabledkey is read from layers 1 to 3 only. Theenabled: truewritten in the media entries is ignored; it cannot switch on a gallery that the control file switches off. -
Media content needs a rebuild. The images and videos of
gallery_media.ymlare written into the HTML data file when the site is built. After a change in the control file or the media file, rebuild the site.
| To see the final settings of a gallery after the merge, open the browser console (F12) and type: |
The keys of a gallery entry
These keys sit at the top level of a gallery entry in gallery_control.yml, outside the blocks described later.
| Key | Default | Description |
|---|---|---|
| false | Shows the gallery ( |
| - | The unique name of the gallery. It names the gallery element on the page, all elements of the manage bar, and the browser storage entries of the gallery. It must be the same in the control file, in the media file and in the page macro |
| - |
|
| - | Video galleries only: |
| - | Video galleries with |
| - | The folder of the images (image galleries) or of the poster images (video galleries). It is used in two places: for every static image of the media file ( |
| - | For information only. Neither the data file nor the adapter reads this key; the poster folder is |
| Give |
Storage: saving items in the browser
The storage block saves the items of a gallery in the browser (localStorage, key jg_gallery_<id>). Each saved item carries everything the gallery needs to rebuild the tile: the image address, the thumbnail, the caption, the size, and the extra values the lightbox reads. So a saved item opens in lightGallery and in PhotoSwipe just like an item of the media file.
The idea is the same as the playlist of the J1 xVideo: the player keeps its playlist in the browser and offers a bar with a list and an editor. The gallery does the same for its items.
| Key | Default | Description |
|---|---|---|
| false | Saves the items automatically every time the layout of the gallery is finished. A gallery with the manage bar can save items without this key: then they are saved only when the visitor changes something. |
| null | The name of the browser storage entry. |
| true |
|
| true | Saved items the visitor changed (import, add, edit, rate, remove) replace the items of the media file on the next page load. |
| false | How Import works: |
| true | Clear Gallery removes the saved items (after downloading a backup file) and reloads the page, so the gallery is built from the media file again. |
| [] | CSS classes given to items added by link in the editor. A lightGallery gallery needs |
| false | One or more JSON item files that are loaded into the gallery on every page load (a single name or a list). See below. |
| /assets/data/apps/ | The folder of the preload files. A name that starts with |
| When do saved items win over the media file? Every gallery with |
Preloading items from JSON files
storage.preload fills a gallery from JSON files on the server, the way playlist.preload fills a playlist of the xVideo. It works only for a gallery whose images list in the media file is empty; a gallery with static images skips the preload and writes a warning to the console.
The files are merged into the saved items on every page load: an item is never loaded twice and never overwrites a saved item, so the list can stay in the configuration for good. Items the visitor added are kept. An item the visitor removed comes back on the next load as long as its file is listed, and Clear Gallery loads the files again after the reload.
storage:
preload: [ mega-cities.json, old-times.json ]A preload file is either a plain list of items or the file that Export Gallery writes (see the section Item file format of the MultiGallery user guide).
| The easiest way to create a preload file: build the gallery in the browser (paste links, import), press Export Gallery, and save the downloaded file into the preload folder. |
Manage bar
The manage block builds a bar above the gallery with a title, the number of items, a button on the left that opens the item list, and a button on the right that opens the editor. While one of the two screens is open, the gallery itself is hidden. The bar is built in the browser; the HTML data file is not touched, so switching it on needs no rebuild of the data file.
manage:
enabled: true
title: My Photos
showItemTools: trueBar and screens
| Key | Default | Description |
|---|---|---|
| false | Builds the bar, the item list and the editor. The storage entry of the gallery is created with it; automatic saving still follows |
| null | The title in the bar. |
| true | Adds the number of items to the title: |
| true | Shows the left button (open or close the item list). The list shows every item with thumbnail, caption, size and source. |
| true | Shows the right button (open or close the editor). |
| true | Shows a remove button in every row of the item list. |
| auto | Where the item list and the number in the title come from. |
| 535px | The fixed height of the item list and the editor. A number means pixels; you may also write units like |
| index.json | The index file of the galleries offered by the import list of the editor. A plain file name is looked up in |
| /assets/data/apps/ | The folder of the index file and of the gallery files it names. |
| {} | Replaces the four bar icons by name: |
Choosing a gallery in the import list and pressing Import loads its items into the gallery (replace, or add with storage.mergeMode: true). The loaded items survive a reload.
Item tools and dialogs
Every item can be rated (1 to 5 stars), edited and removed. The buttons for this are shown in the rows of the item list and, with showItemTools: true, as small round buttons on every tile (on mouse over; always visible on touch devices).
The Edit Media Settings dialog has the fields Category, Title, Description, Info Link, Image Link, Thumbnail, Issue Date and Tags. A title is shown as the caption of the tile; an empty title keeps the original caption. For a video item the dialog shows Video Link (a local file or a YouTube link), Poster Image and Video Size (for example 1280-720) instead of the image fields; a changed value is written into the attributes the lightbox player reads.
| Key | Default | Description |
|---|---|---|
| false | Shows the rate, edit and remove buttons on every tile of the gallery. Needs |
| true | Offers the Set Media Rating dialog (star button). The rating is saved with the item. |
| true | Offers the Edit Media Settings dialog (edit button). |
| true | Offers the remove button (trash icon) in the item tools of every tile. It removes the item from the page and from the saved items. The remove button in the item list follows |
| true | Asks before an item is removed (dialog Remove Media Item with the thumbnail, Cancel or Remove). |
| null | The choices of the Category list for image items. |
| null | The choices of the Category list for video items. |
| Rating, editing or removing an item marks the saved items as changed by the visitor. From the next page load on, the saved items are shown instead of the media file ( |
Drop area
The drop area at the top of the editor adds many images at once. It takes image files (also several at once), whole folders, and image links dragged from another browser tab. The browse … button opens a file picker instead.
A browser never tells a web page where a dropped file lives on the disk of the visitor. So J1 maps a dropped file by its name to an address on the web server, below the image folder of the gallery, and then checks that address:
<image_base_url>/<dropBasePath>/<file> <image_base_url>/<dropBasePath>/<folder>/<file> (a whole folder dropped)
Only images the server really delivers are added. Files that are not found are reported below the drop area. In short: copy the image files into that folder on the server first, then drop them.
| Key | Default | Description |
|---|---|---|
| true | Shows the drop area as a section of its own above the paste a link bar of the editor. |
| null | An optional sub folder below |
| true | When a folder is dropped, its name becomes part of the address: |
| 100 | The maximum number of image files per drop. |
| none | What happens to a file that is not found on the server. |
| 100000 | The largest file (in bytes, about 100 KB) that |
| true | Closes the editor after a drop that added items without errors. Otherwise the editor stays open and shows the result. |
|
|
Runtime menu of the drop area
A small menu button (three dots) at the top right of the drop area opens a menu to change the two parts of the address — the image folder and the sub folder — for the current gallery while the page is open. The YAML files are not changed; Reset in the menu returns to their values. A changed folder is marked runtime in the info line of the drop area.
| Key | Default | Description |
|---|---|---|
| false | Shows the menu button and the menu. The shipped galleries |
| true | Remembers the changed values per gallery in the browser (storage entry |
Retired keys
Two keys of older versions are still in the defaults file but are no longer read; they are kept for reference only:
| Key | Replaced by |
|---|---|
|
|
|
|
Search and sort
The search block adds a search field and a sort list above the gallery (below the manage bar, when there is one). The search looks at the title, description, category, tags, type, caption and alt text of every item and shows only the matching tiles. Several words must all match; words in quotes, like "New York", are searched together. The search bar is hidden while the editor is open. It works for every gallery, also without the manage bar.
| Key | Default | Description |
|---|---|---|
| false | Shows the search bar. |
| (help text) | The gray help text inside the empty search field. |
| true | Shows the sort list. |
| null | Which sort choices are offered, and in which order. |
| none | The sort order on the first page load. |
| true | Remembers the chosen sort order in the browser for the next visit. The search text is not remembered. |
| true | Shows "n items found" while a search is active. |
| 300 | How long (in milliseconds) to wait after the last key press before searching. Enter searches at once, Esc clears the search. |
| The shipped manager gallery has a key |
Lightbox settings
The lightbox block chooses the lightbox of a gallery. Only the type is usually written; enabled: true is inherited from the defaults.
| Key | Default | Description |
|---|---|---|
| true | Opens a lightbox when a tile is clicked. Leave it at |
| lg |
|
The two main lightboxes read different blocks of the gallery entry. The block of the other lightbox is merged but never used, so a gallery can keep both blocks and switch between the lightboxes with one line:
lightbox.type | Blocks that are read |
|---|---|
|
|
|
|
Some settings exist on both sides under different names:
| lightGallery key | PhotoSwipe key |
|---|---|
|
|
|
|
|
|
|
|
|
|
Video galleries with lightGallery
A video gallery on lightbox.type: lg plays its videos in VideoJS when these keys are set in the lightGallery block:
| Key | Description |
|---|---|
| Use the VideoJS player (default |
| The player theme, for example |
| Switches the VideoJS options on (default |
| Uses the subtitle and chapter files of the videos. |
| Keyboard control. Written at the top level of |
| Skip buttons; |
| Zoom buttons; |
| Parameters for YouTube embeds, for example |
Customized thumbnails need three options together: options.addClass: lg-uno-thumbnails, options.appendThumbnailsTo: .lg-outer and options.allowMediaOverlap: true.
PhotoSwipe settings
A gallery with lightbox.type: ps is configured in the photoswipe block. The keys below are merged over the site-wide PhotoSwipe settings (_data/modules/defaults/photoswipe.yml) for this one gallery.
| What has to be on the page. Video galleries need the |
General keys
| Key | Default | Description |
|---|---|---|
| false | Measures the real size of the images instead of trusting |
| (absent) | The full-screen button of this gallery. Three states: |
| (absent) | The caption plugin of this gallery, with the same three states. |
| below | Where the caption is shown: |
| - | Extra space above and below portrait images: |
Fullscreen options
| Key | Default | Description |
|---|---|---|
| - | The same switch as |
| Toggle fullscreen | The tooltip of the button. |
| false | A double click or double tap toggles full screen. Costs: a double tap on a touch screen no longer zooms (pinch still does), and every single click is delayed by |
| 300 | The delay in milliseconds (0 to 2000). |
| (player controls, | A CSS selector of elements where a double click does nothing. A value here replaces the default list. |
| The PhotoSwipe option |
Video options
The block photoswipe.videoOptions is merged over the video defaults of the gallery defaults file.
| Key | Default | Description |
|---|---|---|
| false | Switches the video plugin on for this gallery. Required for every PhotoSwipe video gallery; without it every slide is loaded as an image (a black frame) and the player settings are never used. |
| startOnFirst |
|
| '' (muted) | By default videos start muted; the empty string writes the bare attribute |
| true | When the first start of a video fails silently (YouTube), mute the video and try once more, so the slide starts without sound instead of showing the poster with a spinner. |
| 1200 | How long (milliseconds) to wait for a start before the muted retry. Raise it on slow connections. |
| true | Uses the subtitle and chapter files of the videos ( |
| 40 | The height (px) of the strip at the bottom of a slide where a drag does not change the slide, so the player controls can be used. YouTube galleries use |
| true | Use the VideoJS player for videos marked |
| vjs-theme-uno | The player theme. |
| true | Builds the control bar in the uno layout (time, progress bar and duration in one row), the same bar lightGallery shows. |
| see | Options handed to the VideoJS player as they are (controls, preload, playback rates, control bar). |
| see | The extra controls, each with |
| For |
photoswipe:
videoOptions:
enabled: true
autoplay: startOnFirst
videoAttributes:
muted: false
videojs:
plugins:
skipButtons:
options:
forward: 5
backward: 5
videoFilters:
enabled: true
options:
persist:
scope: player
key: myVideosMedia content
The entries of gallery_media.yml hold the content of a gallery. An image gallery has a list images, a video gallery a list videos. The enabled key of a media entry is ignored; only the control file switches a gallery on.
Images
One - image: entry per image. The list is left empty on purpose for a gallery that gets its items from JSON files or from the browser (like the manager).
| Key | Description |
|---|---|
| The file name below |
| The real size of the image in pixels. The lightbox needs it to place the image. Write |
| The caption of the tile (also used as the alt text). HTML entities like |
| The caption in the lightbox. HTML is allowed. |
Videos
One - video: entry per video.
| Key | Description |
|---|---|
| Shows ( |
| The name used in the share texts. |
|
|
| The player: |
| The size of the video as |
| HTML5: the file name below |
| The picture on the tile, a file below |
| The prefixes of the share texts. |
| As for images. |
| A list of text tracks (subtitles, captions, chapters), see below. On PhotoSwipe the list is used only with |
| lightGallery with YouTube only: the second to start at. PhotoSwipe has no equivalent. |
Every text track is one - track: entry:
| Key | Description |
|---|---|
|
|
|
|
| The language code of the track, for example |
| The name shown in the player menu. |
| The path of the |
| The media entries have the same shape for both lightboxes. To move a gallery from lightGallery to PhotoSwipe, change |
Galleries shipped with J1
The shipped configuration files contain these galleries. Their entries are good examples to copy from:
Gallery id | What it is |
|---|---|
| Image gallery, PhotoSwipe, manage bar and search, no images in the media file (filled from JSON files or the browser). The manager on this page. |
| Image gallery, PhotoSwipe, saved in the browser, ten static images. The viewer on this page. |
| Video gallery with your own video files, lightGallery with VideoJS. |
| Video gallery with your own video files, PhotoSwipe, starts with sound, video filters. |
| Video gallery with YouTube videos, PhotoSwipe, falls back to a muted start. Present in the media file; add a control entry to use it. |