Spotlight.js

Lightbox gallery library

README

Spotlight.js: Modern HTML5 Gallery for Images, Videos and Media

Web's most easy to integrate lightbox gallery library. Super-lightweight, outstanding performance, no dependencies.

Demo  •  Getting Started  •  Gallery Groups  •  Options  •  Styling  •  API  •  Changelog

Whats new in 0.7.0?


The new version includes tons of fixes, new features and improvements which was collected over the last two years. Read the Changelog to get all new features.

Live Demo:

https://nextapps-de.github.io/spotlight/


Spotlight runs out of the box:

- No additional Javascript coding
- No additional HTML snippets
- No additional CSS resources
- No additional icons/assets
- No additional handling of dynamic content and event listener

Features


- Video Support
- Mounting HTML node fragments as slides (you can add just everything as a slide!)
- Gallery groups:
  - group images to specific galleries
  - group options inheritance
- Toolbar & Gallery tools:
  - Fullscreen
  - Zoom in/out
  - Toggle resize
  - Switch theme
  - Autoslide
  - Download
  - Progress Bar
  - Page
  - Title (also inherits from image "alt"-attribute)
  - Description
  - Customizable button
- Adaptive responsive images (by viewport size, pixel ratio and available internet bandwidth)
- Auto-fit images and videos (as "contain" or as "cover")
- Custom Controls
- Fully configurable via markup
- Loading Spinner
- Smart Preloading (prefetch next image including cancellation)
- Customize via standard options
- Simply customize via markup (data-attributes)
- Built-in animations
- Custom themes
- Custom animations
- Supported controls:
  - Keyboard
  - Touch
  - Mouse (Move + Wheel)
- Back-Button (Android)
- Callbacks (onclick, onshow, onclose, onchange)
- Global API for programmatic usage

__Technical properties:__

- Outstanding performance
- Memory optimized, tiny footprint, fully cleans up
- Event capturing (just one single global event listener)
- Bind additional global event listener dynamically:
  - install when gallery opens
  - cleanup when gallery was closed
- No dependencies, no jQuery
- Fully Responsive
- Touch-friendly mobile support
- Super-lightweight, all in all just 9kb gzip (js + css + html + icons)
- Support for ES6 module system

Pending Feature Suggestions:


- Inline Gallery
- Pinch Zoom Support
- 2-Panel-Paging Strategy
- Swipe down to close

Getting Started


__Get Latest Stable Build (Recommended):__

Bundle: (all assets bundled into one single file: js + css + html + icons)
spotlight.bundle.js Download https://rawcdn.githack.com/nextapps-de/spotlight/0.7.8/dist/spotlight.bundle.js

Non-Bundled: (js and css are separated, css includes icons as base64)
spotlight.min.js Download https://rawcdn.githack.com/nextapps-de/spotlight/0.7.8/dist/js/spotlight.min.js
spotlight.min.css Download https://rawcdn.githack.com/nextapps-de/spotlight/0.7.8/dist/css/spotlight.min.css

Sources: (not bundled at all, images as url to original resources)
ES6 Modules Download The /src/js folder of this Github repository
LESS Files (source) Download The /src/css folder of this Github repository
spotlight.css (compiled) Download https://rawcdn.githack.com/nextapps-de/spotlight/0.7.8/src/css/spotlight.css
src.zip Download Download all source files including image original resources.

__Get Latest (NPM):__

  1. ```cmd
  2. npm install spotlight.js
  3. ```

__Get Latest Nightly (Do not use for production!):__

Just exchange the version number from the URLs above with "master", e.g.: "/spotlight/__0.7.8__/dist/" into "/spotlight/__master__/dist".

If you are using markup on anchor elements to inject the library, then it is recommended to load the lib inside your head section of the document. Because that will better prevent the original behavior of the anchor tag (e.g. when library wasn't fully loaded on page start).


Use Bundled Version


The bundled version includes all assets like js, css, html and icon images as base64.

  1. ``` html
  2. <html>
  3. <head>
  4.     <script src="spotlight.bundle.js"></script>
  5. </head>
  6. <body></body>
  7. </html>
  8. ```

Use Non-Bundled Version


The non-bundled version needs to load js and css separately (css also includes icons as base64).

  1. ``` html
  2. <html>
  3. <head>
  4.     <link rel="stylesheet" href="spotlight.min.css">
  5.     <script src="spotlight.min.js"></script>
  6. </head>
  7. <body></body>
  8. </html>
  9. ```

Preload Library / Async Load


If you are using markup on anchor elements to inject the library, then it is recommended to load the lib inside your head section of the document. Read example above.


Just add a link tag to the header sections which indicated to preload the script. Right before the body is closing add your site scripts. Depending on your code you may need to load them in the right order.

  1. ``` html
  2. <html>
  3. <head>
  4.     <title></title>
  5.     <link rel="preload" href="spotlight.bundle.js" as="script">
  6. </head>
  7. <body>
  8.     <!--
  9.     
  10.     HTML CONTENT
  11.     
  12.     -->
  13.     
  14.     <script src="spotlight.bundle.js" defer></script>
  15.     
  16.     <script src="my-script.js" defer></script>
  17. </body>
  18. </html>
  19. ```

You can also load the non-bundled version in the same way.

In rare situations it might produce a short flashing/reflow after page load, depending on your stack. Moving the script tag into the head section will solve this issue. Also try to use the non-bundled version.


ES6 Modules


The ES6 modules are located in src/js/. You need to load the stylesheet file explicitly (includes icons as base64).

  1. ``` html
  2. <head>
  3.     <link rel="stylesheet" href="dist/css/spotlight.min.css">
  4. </head>
  5. ```

  1. ``` html
  2. <script type="module">
  3.   import Spotlight from "./src/js/spotlight.js";
  4. </script>
  5. ```

You can also load modules via CDN, e.g.:

  1. ``` html
  2. <script type="module">
  3.   import Spotlight from "https://unpkg.com/spotlight@0.7.8/src/js/spotlight.js";
  4. </script>
  5. ```

The ES6 modules are not minified. Please use your favored bundler or build tool for this purpose.

Basic Usage (Markup)


Anchor + Images


The most simple way is the combination of img tags as preview images (thumbs) wrapped in an anchor element which points to the fully sized image. The advantage of this workaround is it fully falls back to a classical behavior. It is the universal markup language which all web tools already understand. Therefore, it may have some advantages for SEO also.

Just add the class ___spotlight___ to an anchor element accordingly, e.g.:

  1. ``` html
  2. <a class="spotlight" href="img1.jpg">
  3.     <img src="thumb1.jpg">
  4. </a>
  5. <a class="spotlight" href="img2.jpg">
  6.     <img src="thumb2.jpg">
  7. </a>
  8. <a class="spotlight" href="img3.jpg">
  9.     <img src="thumb3.jpg">
  10. </a>
  11. ```

This also works with dynamically loaded content. There is no need to inject listeners on new elements. Instead, Spotlight make use of global event capturing.


Non-Anchor Elements


Alternatively you can use non-anchor elements also:

  1. ``` html
  2. <div class="spotlight" data-src="img1.jpg">
  3.     
  4. </a>
  5. ```

Pretty much the same like anchors but uses ___data-src___ instead of ___href___.

Gallery-Groups


Grouping galleries is useful when you have multiple images on your page which should be separated into groups, instead of adding all images to one single gallery when opened.

Give one of the outer wrapping element the class ___spotlight-group___, e.g.:

  1. ``` html
  2. <div class="spotlight-group">
  3.     <a class="spotlight" href="dog1.jpg">
  4.         <img src="dog1-thumb.jpg">
  5.     </a>
  6.     <a class="spotlight" href="dog2.jpg">
  7.         <img src="dog2-thumb.jpg">
  8.     </a>
  9.     <a class="spotlight" href="dog3.jpg">
  10.         <img src="dog3-thumb.jpg">
  11.     </a>
  12. </div>
  13. <div class="spotlight-group">
  14.     <a class="spotlight" href="cat1.jpg">
  15.         <img src="cat1-thumb.jpg">
  16.     </a>
  17.     <a class="spotlight" href="cat2.jpg">
  18.         <img src="cat2-thumb.jpg">
  19.     </a>
  20.     <a class="spotlight" href="cat3.jpg">
  21.         <img src="cat3-thumb.jpg">
  22.     </a>
  23. </div>
  24. ```

Each of these groups now opens in its own gallery.

Gallery-Groups are also useful to declare global configuration as markup just once (group options inheritance).

Basic Usage (API)


Also you can programmatically use Spotlight via the library API. This way does not require any dependant HTML elements (e.g. the classname "spotlight").

Define a gallery group as follows:

  1. ``` js
  2. var gallery = [
  3.     { src: "cat1.jpg" },
  4.     { src: "cat2.jpg" },
  5.     { src: "cat3.jpg" }
  6. ];
  7. ```

Show gallery with default options:

  1. ``` js
  2. Spotlight.show(gallery /*, options */);
  3. ```

Options


Pass options declarative via data-attributes in the HTML markup or use the Spotlight API.

When using markup follow these style: data-option="value" (change _option_ and _value_ accordingly), e.g.: <a class="spotlight" data-preload="false"></a>.


When using API follow thse style { option: value } (change _option_ and _value_ accordingly), e.g.: { preload: false }.


You can either apply the following data-attributes to the ___spotlight-group___ wrapper element or apply them separately to each ___spotlight___ anchor element (that also overrides inherited group definitions).

When using API the ___spotlight-group___ is represented by the options payload, also you can assign attributes separately to each gallery entry (that also overrides inherited group definitions).

Option         Values Description Default
class
            string
            Set a classname to this gallery instance to apply custom styles besides themes independently.
null
media "image"
"video"
            "node"
            Sets the the type of the media which should be added to the page.
image
animation string
Array<string>
"fade"
"slide"
"scale"
Change animation (use built-ins or custom classname)
Note: Markup as comma-separated list, e.g: data-animation="slide,fade,scale".
slide, fade, scale
control string
            Array<string>
Show/hide control elements as "whitelisted" through a comma-separated list, e.g. data-control="autofit,page,fullscreen" page, zoom, autofit, fullscreen, close
page true / false Show/hide page in the toolbar true
fullscreen true / false Show/hide fullscreen button (automatically hides when not supported by the browser) true
zoom true / false Show/hide both zoom buttons in the toolbar true
zoom-in true / false Show/hide zoom-in button in the toolbar true
zoom-out true / false Show/hide zoom-out button in the toolbar true
autofit true / false Show/hide autofit button in the toolbar true
close true / false Show/hide the close icon in the toolbar true
theme true / false Show/hide theme button false
play true / false / number Show/hide play button. When passing a numeric value it will be used as a delay in seconds between each tick. false
autoslide true / false Autoslide when opening gallery. false
progress true / false Show/hide the animated autoslide progress bar true
infinite true / false Restart from beginning when no slides left false
autohide true / false / number Enable/disable automatically hide controls when inactive, also set cooldown time in seconds. 7
theme string
"white"
The classname of your custom theme. The theme "white" is a built-in theme. null
title string / false Set image title or hide it
Note: When using image elements, this attribute will also inherit automatically from <img alt="..."> as well as from <img title="...">. To prevent this behavior you can set data-title="false" explicitly. This will hide the title regardless of any image alt-attributes.
null
description string / false Set image description or hide it null
spinner true / false Enable/disable the spinner. When disabled the image will not hide until it is fully loaded, that could be useful for progressive jpeg. true
button str Enable/disable a button in the footer section, also set button text.
Note: When using as markup you have to provide a click target for the button or you can assign an onclick callback via options when used programmatically.
null
button-href str When using a button as markup you can provide a click target for the button, e.g. <a button="click me" button-href="https://domain.com" target="_blank" rel="nofollow noopener noreferrer">. null

Additional Image Options


Option         Values Description Default
src-{size} src-1200
src-2400
src-3800
            ...
The tag/key represents the size of the image longest side. The content contains the path or url to the image (e.g. data-src-800="image_800x400.jpg"). null
preload true / false Enable/disable preloading of the next image true
fit "contain"
"cover"
Auto-fit the media either as "contain" or as "cover" contain
download true / false Show/hide the download icon in the toolbar false

Additional Video Options


Most of these options for a video are inherited by the attributes of a standard video element.

Option         Values Description Default
src-{format} src-webm
src-ogg
src-mp4
            ...
The tag/key represents the format of the video. The content contains the path or url to the video (e.g. data-src-webm="video.webm"). null
fit "contain"
"cover"
Auto-fit the media either as "contain" or as "cover" contain
autoplay true
            false
            Start the video immediately.
false
muted true
            false
            Start playing as muted.
false
preload true
            false
            Preload the video.
false
controls true
            false
            Show/hide the video controls.
true
inline true
            false
            Make the video player inline (equal to "playsinline").
false
poster
            string
            The path or URL to the preview image.
null

API-only Options


Option         Values Description Default
index
            number
Sets the starting index when showing the gallery by using the Spotlight API. The index starts from 1. 1
onchange
            function(index, options)
Pass a callback function which is get fired every time when a page/slide has changed. The first parameter holds the new page index, the second parameter provides the inherited option payload for this page.
Note: The image may not have been fully loaded when the event is fired (preloading phase). The index starts from 1.
null
onshow
onclose
            function(index)
            These callback functions are called when opening or closing the gallery (the first parameter holds the current page index).
null
onclick
            function(index, options)
            A callback function which is getting fired when the optional button in the footer sections was clicked. The first parameter holds the current page index, the second parameter provides the inherited option payload for this page.
null

Example: Options & Group Inheritance (Markup)


  1. ``` html
  2. <div class="spotlight-group" data-title="Group title" data-animation="fade" data-control="autofit,close">
  3.     <a class="spotlight" href="cat1.jpg" data-title="This is a title" data-theme="white">
  4.         <img src="cat1-thumb.jpg">
  5.     </a>
  6.     <a class="spotlight" href="cat2.jpg" data-description="This is a description">
  7.         <img src="cat2-thumb.jpg">
  8.     </a>
  9.     <a class="spotlight" href="cat3.jpg" data-button="Click me" data-button-href="javascript:alert('clicked')">
  10.         <img src="cat3-thumb.jpg" alt="This is also a title">
  11.     </a>
  12.     <a class="spotlight" href="cat4.jpg" data-title="false" data-fit="cover">
  13.       <img src="cat4-thumb.jpg" alt="This title is hidden">
  14.     </a>
  15. </div>
  16. ```

__Note:__ The 2nd image gets the title "Group title" from the group attributes, on the last image the title is explicitly set to be hidden.

Control elements and animations has to be __whitelisted__ as a comma-separated list when specified. Do not forget to add the "close" control, otherwise you need to provide another way to close the gallery, e.g. via the button in the footer (see the demo page bottom example).


Example: Options & Group Inheritance (API)


Same result as above but as code:

  1. ``` js
  2. Spotlight.show([{
  3.     src: "cat1.jpg",
  4.     title: "This is a title",
  5.     theme: "white"
  6. },{
  7.     src: "cat2.jpg",
  8.     description: "This is a description",
  9. },{
  10.     src: "cat3.jpg",
  11.     button: "Click me",
  12.     onclick: function(){ alert("clicked"); },
  13.     title: "This is also a title"
  14. },{
  15.     src: "cat4.jpg",
  16.     title: false,
  17.     fit: "cover"
  18. }],{
  19.     // Group Definitions:
  20.     title: "Group title",
  21.     animation: "fade",
  22.     control: "autofit,close"
  23. });
  24. ```

Adaptive Responsive Images


This feature will improve overall performance of your page/application a lot, especially for mobile devices and bad internet connections.


You can declare a set of the same image in multiple dimensions and quality. Spotlight will pick the optimal version by taking into account:

1. The browsers max resolution
2. The device screen pixel ratio
3. The available internet connection bandwidth

Example: Markup


Save your images in several sizes and resolutions and assign the __longest__ dimension of both sides (width, height) like this:
  1. ``` html
  2. <a class="spotlight" href="cat1.jpg" 
  3.                      data-src-800="cat1_800.jpg" 
  4.                      data-src-1200="cat1_1200.jpg" 
  5.                      data-src-2400="cat1_2400.jpg" 
  6.                      data-src-3800="cat1_3800.jpg">
  7.     <img src="cat1-thumb.jpg">
  8. </a>
  9. ```

When clicked on it Spotlight will pick the optimum choice.

This markup completely falls back to standard browser behavior when something goes wrong, also it is SEO friendly.

Example: API


Same result as above but as code:

  1. ``` js
  2. Spotlight.show([{
  3.     // the default "href" version as fallback isn't required here
  4.     "src-800": "cat1_800.jpg",
  5.     "src-1200": "cat1_1200.jpg",
  6.     "src-2400": "cat1_2400.jpg",
  7.     "src-3800": "cat1_3800.jpg"
  8. }]);
  9. ```

Support Video


All data-attributes for markup a video is inherited by the attributes of a standard video element.


Considering you want to add a standard video element like this as a slide:

  1. ``` html
  2. <video poster="preview.jpg" muted preload controls autoplay playsinline="false">
  3.     <source src="video.mp4" type="video/mp4">
  4.     <source src="video.ogv" type="video/ogg">
  5.     <source src="video.webm" type="video/webm">
  6. </video>
  7. ```

Example: Markup


You need a markup like this to represent the video from above:

  1. ``` html
  2. <a class="spotlight" data-media="video"
  3.                      data-src-webm="video.webm"
  4.                      data-src-ogg="video.ogv"
  5.                      data-src-mp4="video.mp4"
  6.                      data-poster="preview.jpg"
  7.                      data-autoplay="true"
  8.                      data-muted="true"
  9.                      data-preload="true"
  10.                      data-controls="true"
  11.                      data-inline="false">
  12.   <img src="preview.jpg">
  13. </a>
  14. ```

Example: API


Same result as above but as code:

  1. ``` js
  2. Spotlight.show([{
  3.   
  4.   "media": "video",
  5.   "src-webm": "video.webm",
  6.   "src-ogg": "video.ogv",
  7.   "src-mp4": "video.mp4",
  8.   "poster": "preview.jpg",
  9.   "autoplay": true,
  10.   "muted": true,
  11.   "preload": true,
  12.   "controls": true,
  13.   "inline": false
  14. }]);
  15. ```

Custom Controls


You can add custom controls to the header toolbar by API usage only.


The basic concept is very straight forward. You just need to assign a unique classname along with an event listener. Basically you have to follow these steps.

1. Initialize the Spotlight gallery manually __once__ to make the template available for extensions:
  1. ``` js
  2. Spotlight.init();
  3. ```

The gallery automatically initialize when first time open, so you can also add custom control inside the "onshow" callback.

2. Add the custom control and pass a click handler (returns the button element):
  1. ``` js
  2. var button = Spotlight.addControl("my-control", function(event){
  3.     // handle click event
  4.     console.log("button clicked");
  5. });
  6. ```

3. Define a CSS class to style your button:
  1. ```css
  2. /* your control name will be prefixed by "spl-" automatically */
  3. .spl-my-control{
  4.     background-image: url(icon.svg);
  5.     background-size: 22px;
  6. }
  7. ```

Important: custom control classes gets always css-prefixed by "spl-" automatically to prevent classname collision!


Removing an added control:

  1. ``` js
  2. Spotlight.removeControl("my-control");
  3. ```

Advanced Example (Like Button)


Let's take a useful example of dynamically adding a "like button" in the toolbar. You can see a live demo of this example on the demo page (bottom section).

Providing a gallery as normal and add a custom attribute "like", which stores the current like state of each image.
  1. ``` js
  2. const gallery = [{

  3.     src: "image1.jpg",
  4.     like: false
  5. },{
  6.     src: "image2.jpg",
  7.     like: false,
  8. },{
  9.     src: "image3.jpg",
  10.     like: false
  11. }];
  12. ```

Define a CSS class to style your button, e.g.:
  1. ```css
  2. /* custom classes are always prefixed by "spl-" automatically */
  3. .spl-like{
  4.     background-image: url(heart-outline.svg);
  5.     background-size: 22px;
  6. }
  7. /* optionally, additional state to toggle the button: */
  8. .spl-like.on{
  9.     background-image: url(heart.svg);
  10. }
  11. ```

Please keep in mind, when your custom control has the name "like" the corresponding classname always gets prefixed by "spl-" and becomes "spl-like" to prevent classname collision. Do not name your control in prefixed style like "spl-like", because that will prefix this also (and becomes "spl-spl-like").


We need some variables to store some state which is used in the callback handler later:
  1. ``` js
  2. // store the button element to apply dom changes to it
  3. let like;
  4. // store the current index
  5. let slide = 0;
  6. ```

Implement a click event handler of the like button, e.g.:
  1. ``` js
  2. function handler(event){
  3.   
  4.     // get the current like state
  5.     // at this point we use the stored last index from the variable "slide"
  6.     const current_like_state = !gallery[slide].like;
  7.   
  8.     // toggles the current like state
  9.     gallery[slide].like = current_like_state;
  10.   
  11.     // assign the state as class to visually represent the current like state
  12.     this.classList.toggle("on");
  13.   
  14.     if(current_like_state){
  15.   
  16.       // do something if liked ...
  17.     }
  18.     else{
  19.   
  20.       // do something if unliked ...
  21.     }
  22. }
  23. ```

The keyword this corresponds to the current clicked element (the like icon in this example).


Finally, create the gallery and provide some callbacks to insert the custom control dynamically:
  1. ``` js
  2. Spotlight.show(gallery, {

  3.     // fires when gallery opens
  4.     onshow: function(index){

  5.         // the method "addControl" returns the new created control element
  6.         like = Spotlight.addControl("like", handler);
  7.     },
  8.     // fires when gallery change to another page
  9.     onchange: function(index, options){

  10.         // store the current index for the button listener
  11.         // the slide index start from 1 (as "page 1")
  12.         slide = index - 1;

  13.         // initially apply the stored like state when slide is openened
  14.         // at this point we use the stored like element
  15.         like.classList.toggle("on", gallery[slide].like);
  16.     },
  17.     // fires when gallery is requested to close
  18.     onclose: function(index){

  19.         // remove the custom button, so you are able
  20.         // to open next gallery without this custom control
  21.         Spotlight.removeControl("like");
  22.     }
  23. });
  24. ```

You did not need to remove the custom control everytime. When all your galleries have this custom control, then simply add the control after you call Spotlight.init() once.

Initialize the Spotlight gallery once:
  1. ``` js
  2. Spotlight.init();
  3. ```

Add the custom control once:
  1. ``` js
  2. like = Spotlight.addControl("like", handler);
  3. ```

Open the gallery and just provide an "onchange" handler:
  1. ``` js
  2. Spotlight.show(gallery, {
  3.     onchange: function(index, options){
  4.         slide = index - 1;
  5.         like.classList.toggle("on", gallery[slide].like);
  6.     }
  7. });
  8. ```

That is the same custom like button from above example, just shorter but also non-dynamically added for all gallery instances.

Embedding Node Fragments


With node fragments you can simply add everything as a slide. This way you can create your own full customized slides with its own interactions inside them.


You can use this feature completely by markup by providing a query selector as "src" which points to a node in your document.

Using Auto-Mount / Auto-Unmount


This workaround is also compatible if you are using server-side rendering.


You can use a hidden backstore optionally which holds the fragments to be inserted as a slide, e.g.:

  1. ``` html
  2. <div style="display: none">
  3.     <div id="fragment" style="width: 100%">
  4.         <h1>Embedded Node Fragment</h1>
  5.         <p>Any HTML Content...</p>
  6.     </div>
  7. </div>
  8. ```

Provide a __dom query selector__ as "src" which points to a node in your document:
  1. ``` html
  2. <a class="spotlight" data-media="node" data-src="#fragment">
  3.     Click here to open
  4. </a>
  5. ```

When closing the gallery or change the page to another slide, the fragment will automatically move back to its original position (the hidden backstore in this example).

Custom Slides (API)


You can add nodes as slide which are not part of the document via the API (e.g. fragments, templates, offscreen nodes). Also, you can create an iframe to load extern contents.

Example: Youtube Video


You can create your own fragments/templates and add the root node directly as "src":

  1. ``` js
  2. Spotlight.show([{
  3.     media: "node",
  4.     src: (function(){
  5.         const iframe = document.createElement("iframe");
  6.         iframe.src = "https://www.youtube.com/embed/tgbNymZ7vqY";
  7.         return iframe;
  8.     }())
  9. }]);
  10. ```

Example: Templating Engine


Or use your preferred templating engine and add the root node as "src":

  1. ``` js
  2. Mikado(template).mount(root).render(data);

  3. Spotlight.show([{
  4.     media: "node",
  5.     src: root
  6. }]);
  7. ```

Spotlight API


Define a gallery group as follows:

  1. ``` js
  2. var gallery = [{
  3.     title: "Image 1",
  4.     description: "This is a description.",
  5.     src: "gallery/london-1758181.jpg"
  6. },{
  7.     title: "Image 2",
  8.     description: "This is a description.",
  9.     src: "gallery/sea-1975403.jpg"
  10. },{
  11.     title: "Image 3",
  12.     description: "This is a description.",
  13.     src: "gallery/newport-beach-2089906.jpg"
  14. }];
  15. ```

Show gallery with default options:

  1. ``` js
  2. Spotlight.show(gallery);
  3. ```

Show gallery with custom options:

  1. ``` js
  2. Spotlight.show(gallery, {
  3.     index: 2,
  4.     theme: "white",
  5.     autohide: false,
  6.     control: ["autofit", "zoom", "close"]
  7. });
  8. ```

Close gallery:

  1. ``` js
  2. Spotlight.close();
  3. ```

Next slide:

  1. ``` js
  2. Spotlight.next();
  3. ```

Previous slide:

  1. ``` js
  2. Spotlight.prev();
  3. ```

Goto slide:

  1. ``` js
  2. Spotlight.goto(3);
  3. ```

Zoom to:

  1. ``` js
  2. Spotlight.zoom(1.5);
  3. ```

Toggle theme:

  1. ``` js
  2. Spotlight.theme();
  3. ```

Set theme:

  1. ``` js
  2. Spotlight.theme("white");
  3. ```
  1. ``` js
  2. Spotlight.theme("dark");
  3. ```

Toggle fullscreen:

  1. ``` js
  2. Spotlight.fullscreen();
  3. ```

Set fullscreen:

  1. ``` js
  2. Spotlight.fullscreen(true);
  3. ```
  1. ``` js
  2. Spotlight.fullscreen(false);
  3. ```

Toggle autofit:

  1. ``` js
  2. Spotlight.autofit();
  3. ```

Set autofit:

  1. ``` js
  2. Spotlight.autofit(true);
  3. ```
  1. ``` js
  2. Spotlight.autofit(false);
  3. ```

Toggle menu:

  1. ``` js
  2. Spotlight.menu();
  3. ```

Set menu:

  1. ``` js
  2. Spotlight.menu(true);
  3. ```
  1. ``` js
  2. Spotlight.menu(false);
  3. ```

Download current image:

  1. ``` js
  2. Spotlight.download();
  3. ```

Example ES6:


  1. ``` js
  2. import Spotlight from "./spotlight.js";

  3. Spotlight.show(
  4.     [ /* Gallery */ ],
  5.     { /* Options */ }
  6. );
  7. ```

You can also import any of the Spotlight methods just as you need:

  1. ``` js
  2. import { show, close, goto } from "./spotlight.js";

  3. show([/* Gallery */], {/* Options */});
  4. // ....
  5. goto(5);
  6. // ....
  7. close();
  8. ```

Modern build tools will apply dead code elimination when just importing methods your application needs.


Custom Styling


To add custom styling just override CSS classes accordingly:

  1. ```css
  2. #spotlight { /* main font styles, background */ }
  3. .spl-page { /* current page (toolbar) */ }
  4. .spl-fullscreen { /* button fullscreen (toolbar) */ }
  5. .spl-autofit { /* button autofit (toolbar) */ }
  6. .spl-zoom-out { /* button zoom out (toolbar) */ }
  7. .spl-zoom-in { /* button zoom in (toolbar) */ }
  8. .spl-theme { /* button theme (toolbar) */ }
  9. .spl-play { /* button autoplay (toolbar) */ }
  10. .spl-download { /* button download (toolbar) */ }
  11. .spl-close { /* button close (toolbar) */ }
  12. .spl-prev { /* button page prev */ }
  13. .spl-next { /* button page next */ }
  14. .spl-spinner { /* preloading spinner */ }
  15. .spl-spinner.spin { /* show spinner */ }
  16. .spl-spinner.error { /* show loading error */ }
  17. .spl-title { /* image title */ }
  18. .spl-description { /* image description */ }
  19. .spl-button { /* button footer */ }
  20. .spl-header { /* the header wrapping element */ }
  21. .spl-footer { /* the footer wrapping element */ }
  22. ```

Themes


__Customize builtin themes__

Use the same classes as above:

  1. ```css
  2. #spotlight.white .spl-title{
  3.     /* image title in white theme */
  4. }
  5. ```

  1. ```css
  2. #spotlight{
  3.     /* main background in dark theme */
  4. }
  5. ```

__Create New Themes__

Define styles, e.g. for the custom theme name "my-theme":

  1. ```css
  2. .my-theme .spl-title{
  3.     /* image title in custom theme */
  4. }
  5. .my-theme{
  6.     /* main background in custom theme */
  7. }
  8. ```

Apply custom theme via markdown:

  1. ``` html
  2. <a class="spotlight" href="cat.jpg" data-theme="my-theme">
  3.     <img src="cat_thumb.jpg">
  4. </a>
  5. ```

Or apply custom theme via API:

  1. ``` js
  2. Spotlight.show([ /* Gallery */ ],{
  3.     theme: "my-theme"
  4. });
  5. ```

You could also set themes per image separately:

  1. ``` js
  2. Spotlight.show([
  3.     { src: "cat1.jpg" }, // default theme
  4.     { src: "cat2.jpg", theme: "my-theme" },
  5.     { src: "cat3.jpg", theme: "white" }
  6. ]);
  7. ```

CSS Class


If you like to apply styles independently besides themes you can simply do that by adding a class during initialization:
  1. ``` js
  2. Spotlight.show([
  3.     { src: "cat1.jpg" }, // default theme
  4.     { src: "cat2.jpg", theme: "my-theme" },
  5.     { src: "cat3.jpg", theme: "white" }
  6. ],{
  7.     class: "custom"
  8. });
  9. ```

In your stylesheet you can apply you custom styles, .e.g.:

  1. ```css
  2. #spotlight.custom .spl-title{
  3.     font-size: 15px;
  4. }
  5. ```

Custom Animations


Important: The style class for a custom animation describes the __<u>hidden state</u>__ of an image.


You can define your own custom animation by:

1. Define the styles in default state (when image is shown), e.g.:

  1. ```css
  2. .spl-pane > *{
  3.     filter: grayscale(0);
  4.     transition: filter 1s ease-out,
  5.                 opacity 0.5s ease-out;
  6. }
  7. ```

2. Define styles for the __hidden state__ of the transition by adding a custom classname:

  1. ```css
  2. .spl-pane .my-animation{
  3.     filter: grayscale(1);
  4.     opacity: 0;
  5. }
  6. ```

Apply custom animation via markdown:

  1. ``` html
  2. <a class="spotlight" href="cat.jpg" data-animation="my-animation">
  3.     <img src="cat_thumb.jpg">
  4. </a>
  5. ```

Or apply custom animation via API:

  1. ``` js
  2. Spotlight.show([ /* Gallery */ ],{
  3.     animation: "my-animation"
  4. });
  5. ```

You could also set animations per image separately:

  1. ``` js
  2. Spotlight.show([
  3.     { src: "cat1.jpg" }, // default animation
  4.     { src: "cat2.jpg", animation: "my-animation" },
  5.     { src: "cat3.jpg", animation: "slide,fade" }
  6. ]);
  7. ```

Use different animations for galleries


The example above will apply the animation to all instances of your gallery. When you want to add specific animation to each gallery you need to add a class in your options:
  1. ``` js
  2. Spotlight.show([
  3.     { src: "cat1.jpg" },
  4.     { src: "cat2.jpg" },
  5.     { src: "cat3.jpg" }
  6. ],{
  7.   animation: "my-animation",
  8.   class: "custom"
  9. });
  10. ```

Then, add your classname (context selector) to your CSS for the ___visible___ state of the animation:

  1. ```css
  2. .custom .spl-pane > *{
  3.     filter: grayscale(0);
  4.     transition: filter 1s ease-out,
  5.                 opacity 0.5s ease-out;
  6. }
  7. ```

Now you can assign different animations to each gallery.

Custom Builds


Go to the root directory of Spotlight and run:
  1. ```cmd
  2. npm install
  3. ```

Perform a build:
  1. ```cmd
  2. npm run build
  3. ```

The final build is located in the dist/ folder.


Copyright 2019-2021 Nextapps GmbH
Released under the Apache 2.0 License