UNPKG

12.1 kBTypeScriptView Raw
1import { LightGalleryAllSettings, LightGallerySettings } from './lg-settings';
2import { GalleryItem, ImageSize } from './lg-utils';
3import { lgQuery } from './lgQuery';
4import { Coords, MediaContainerPosition, SlideDirection } from './types';
5export declare class LightGallery {
6 settings: LightGalleryAllSettings;
7 galleryItems: GalleryItem[];
8 lgId: number;
9 el: HTMLElement;
10 LGel: lgQuery;
11 lgOpened: boolean;
12 index: number;
13 plugins: any[];
14 lGalleryOn: boolean;
15 lgBusy: boolean;
16 touchAction?: 'swipe' | 'zoomSwipe' | 'pinch';
17 swipeDirection?: 'horizontal' | 'vertical';
18 hideBarTimeout: any;
19 currentItemsInDom: string[];
20 outer: lgQuery;
21 items: any;
22 $backdrop: lgQuery;
23 $lgComponents: lgQuery;
24 $container: lgQuery;
25 $inner: lgQuery;
26 $content: lgQuery;
27 $toolbar: lgQuery;
28 prevScrollTop: number;
29 bodyPaddingRight: number;
30 private zoomFromOrigin;
31 private currentImageSize?;
32 private isDummyImageRemoved;
33 private dragOrSwipeEnabled;
34 mediaContainerPosition: {
35 top: number;
36 bottom: number;
37 };
38 constructor(element: HTMLElement, options?: LightGallerySettings);
39 private generateSettings;
40 private normalizeSettings;
41 init(): void;
42 openGalleryOnItemClick(): void;
43 /**
44 * Module constructor
45 * Modules are build incrementally.
46 * Gallery should be opened only once all the modules are initialized.
47 * use moduleBuildTimeout to make sure this
48 */
49 buildModules(): void;
50 validateLicense(): void;
51 getSlideItem(index: number): lgQuery;
52 getSlideItemId(index: number): string;
53 getIdName(id: string): string;
54 getElementById(id: string): lgQuery;
55 manageSingleSlideClassName(): void;
56 buildStructure(): void;
57 refreshOnResize(): void;
58 resizeVideoSlide(index: number, imageSize?: ImageSize): void;
59 /**
60 * Update slides dynamically.
61 * Add, edit or delete slides dynamically when lightGallery is opened.
62 * Modify the current gallery items and pass it via updateSlides method
63 * @note
64 * - Do not mutate existing lightGallery items directly.
65 * - Always pass new list of gallery items
66 * - You need to take care of thumbnails outside the gallery if any
67 * - user this method only if you want to update slides when the gallery is opened. Otherwise, use `refresh()` method.
68 * @param items Gallery items
69 * @param index After the update operation, which slide gallery should navigate to
70 * @category lGPublicMethods
71 * @example
72 * const plugin = lightGallery();
73 *
74 * // Adding slides dynamically
75 * let galleryItems = [
76 * // Access existing lightGallery items
77 * // galleryItems are automatically generated internally from the gallery HTML markup
78 * // or directly from galleryItems when dynamic gallery is used
79 * ...plugin.galleryItems,
80 * ...[
81 * {
82 * src: 'img/img-1.png',
83 * thumb: 'img/thumb1.png',
84 * },
85 * ],
86 * ];
87 * plugin.updateSlides(
88 * galleryItems,
89 * plugin.index,
90 * );
91 *
92 *
93 * // Remove slides dynamically
94 * galleryItems = JSON.parse(
95 * JSON.stringify(updateSlideInstance.galleryItems),
96 * );
97 * galleryItems.shift();
98 * updateSlideInstance.updateSlides(galleryItems, 1);
99 * @see <a href="/demos/update-slides/">Demo</a>
100 */
101 updateSlides(items: GalleryItem[], index: number): void;
102 getItems(): GalleryItem[];
103 shouldHideScrollbar(): boolean;
104 hideScrollbar(): void;
105 resetScrollBar(): void;
106 /**
107 * Open lightGallery.
108 * Open gallery with specific slide by passing index of the slide as parameter.
109 * @category lGPublicMethods
110 * @param {Number} index - index of the slide
111 * @param {HTMLElement} element - Which image lightGallery should zoom from
112 *
113 * @example
114 * const $dynamicGallery = document.getElementById('dynamic-gallery-demo');
115 * const dynamicGallery = lightGallery($dynamicGallery, {
116 * dynamic: true,
117 * dynamicEl: [
118 * {
119 * src: 'img/1.jpg',
120 * thumb: 'img/thumb-1.jpg',
121 * subHtml: '<h4>Image 1 title</h4><p>Image 1 descriptions.</p>',
122 * },
123 * ...
124 * ],
125 * });
126 * $dynamicGallery.addEventListener('click', function () {
127 * // Starts with third item.(Optional).
128 * // This is useful if you want use dynamic mode with
129 * // custom thumbnails (thumbnails outside gallery),
130 * dynamicGallery.openGallery(2);
131 * });
132 *
133 */
134 openGallery(index?: number, element?: HTMLElement): void;
135 /**
136 * Note - Changing the position of the media on every slide transition creates a flickering effect.
137 * Therefore, The height of the caption is calculated dynamically, only once based on the first slide caption.
138 * if you have dynamic captions for each media,
139 * you can provide an appropriate height for the captions via allowMediaOverlap option
140 */
141 getMediaContainerPosition(): MediaContainerPosition;
142 private setMediaContainerPosition;
143 hideBars(): void;
144 initPictureFill($img: lgQuery): void;
145 /**
146 * @desc Create image counter
147 * Ex: 1/10
148 */
149 counter(): void;
150 /**
151 * @desc add sub-html into the slide
152 * @param {Number} index - index of the slide
153 */
154 addHtml(index: number): void;
155 /**
156 * @desc Preload slides
157 * @param {Number} index - index of the slide
158 * @todo preload not working for the first slide, Also, should work for the first and last slide as well
159 */
160 preload(index: number): void;
161 getDummyImgStyles(imageSize?: ImageSize): string;
162 getVideoContStyle(imageSize?: ImageSize): string;
163 getDummyImageContent($currentSlide: lgQuery, index: number, alt: string): string;
164 setImgMarkup(src: string, $currentSlide: lgQuery, index: number): void;
165 onSlideObjectLoad($slide: lgQuery, isHTML5VideoWithoutPoster: boolean, onLoad: () => void, onError: () => void): void;
166 /**
167 *
168 * @param $el Current slide item
169 * @param index
170 * @param delay Delay is 0 except first time
171 * @param speed Speed is same as delay, except it is 0 if gallery is opened via hash plugin
172 * @param isFirstSlide
173 */
174 onLgObjectLoad(currentSlide: lgQuery, index: number, delay: number, speed: number, isFirstSlide: boolean, isHTML5VideoWithoutPoster: boolean): void;
175 triggerSlideItemLoad($currentSlide: lgQuery, index: number, delay: number, speed: number, isFirstSlide: boolean): void;
176 isFirstSlideWithZoomAnimation(): boolean;
177 addSlideVideoInfo(items: GalleryItem[]): void;
178 /**
179 * Load slide content into slide.
180 * This is used to load content into slides that is not visible too
181 * @param {Number} index - index of the slide.
182 * @param {Boolean} rec - if true call loadcontent() function again.
183 */
184 loadContent(index: number, rec: boolean): void;
185 /**
186 * @desc Remove dummy image content and load next slides
187 * Called only for the first time if zoomFromOrigin animation is enabled
188 * @param index
189 * @param $currentSlide
190 * @param speed
191 */
192 loadContentOnFirstSlideLoad(index: number, $currentSlide: lgQuery, speed: number): void;
193 getItemsToBeInsertedToDom(index: number, prevIndex: number, numberOfItems?: number): string[];
194 organizeSlideItems(index: number, prevIndex: number): string[];
195 /**
196 * Get previous index of the slide
197 */
198 getPreviousSlideIndex(): number;
199 setDownloadValue(index: number): void;
200 makeSlideAnimation(direction: 'next' | 'prev', currentSlideItem: lgQuery, previousSlideItem: lgQuery): void;
201 /**
202 * Goto a specific slide.
203 * @param {Number} index - index of the slide
204 * @param {Boolean} fromTouch - true if slide function called via touch event or mouse drag
205 * @param {Boolean} fromThumb - true if slide function called via thumbnail click
206 * @param {String} direction - Direction of the slide(next/prev)
207 * @category lGPublicMethods
208 * @example
209 * const plugin = lightGallery();
210 * // to go to 3rd slide
211 * plugin.slide(2);
212 *
213 */
214 slide(index: number, fromTouch?: boolean, fromThumb?: boolean, direction?: SlideDirection | false): void;
215 updateCurrentCounter(index: number): void;
216 updateCounterTotal(): void;
217 getSlideType(item: GalleryItem): 'video' | 'iframe' | 'image';
218 touchMove(startCoords: Coords, endCoords: Coords, e?: TouchEvent): void;
219 touchEnd(endCoords: Coords, startCoords: Coords, event: TouchEvent): void;
220 enableSwipe(): void;
221 enableDrag(): void;
222 triggerPosterClick(): void;
223 manageSwipeClass(): void;
224 /**
225 * Go to next slide
226 * @param {Boolean} fromTouch - true if slide function called via touch event
227 * @category lGPublicMethods
228 * @example
229 * const plugin = lightGallery();
230 * plugin.goToNextSlide();
231 * @see <a href="/demos/methods/">Demo</a>
232 */
233 goToNextSlide(fromTouch?: boolean): void;
234 /**
235 * Go to previous slides
236 * @param {Boolean} fromTouch - true if slide function called via touch event
237 * @category lGPublicMethods
238 * @example
239 * const plugin = lightGallery({});
240 * plugin.goToPrevSlide();
241 * @see <a href="/demos/methods/">Demo</a>
242 *
243 */
244 goToPrevSlide(fromTouch?: boolean): void;
245 keyPress(): void;
246 arrow(): void;
247 arrowDisable(index: number): void;
248 setTranslate($el: lgQuery, xValue: number, yValue: number, scaleX?: number, scaleY?: number): void;
249 mousewheel(): void;
250 isSlideElement(target: lgQuery): boolean;
251 isPosterElement(target: lgQuery): boolean;
252 /**
253 * Maximize minimize inline gallery.
254 * @category lGPublicMethods
255 */
256 toggleMaximize(): void;
257 invalidateItems(): void;
258 trapFocus(): void;
259 manageCloseGallery(): void;
260 /**
261 * Close lightGallery if it is opened.
262 *
263 * @description If closable is false in the settings, you need to pass true via closeGallery method to force close gallery
264 * @return returns the estimated time to close gallery completely including the close animation duration
265 * @category lGPublicMethods
266 * @example
267 * const plugin = lightGallery();
268 * plugin.closeGallery();
269 *
270 */
271 closeGallery(force?: boolean): number;
272 initModules(): void;
273 destroyModules(destroy?: true): void;
274 /**
275 * Refresh lightGallery with new set of children.
276 *
277 * @description This is useful to update the gallery when the child elements are changed without calling destroy method.
278 *
279 * If you are using dynamic mode, you can pass the modified array of dynamicEl as the first parameter to refresh the dynamic gallery
280 * @see <a href="/demos/dynamic-mode/">Demo</a>
281 * @category lGPublicMethods
282 * @example
283 * const plugin = lightGallery();
284 * // Delete or add children, then call
285 * plugin.refresh();
286 *
287 */
288 refresh(galleryItems?: GalleryItem[]): void;
289 updateControls(): void;
290 /**
291 * Destroy lightGallery.
292 * Destroy lightGallery and its plugin instances completely
293 *
294 * @description This method also calls CloseGallery function internally. Returns the time takes to completely close and destroy the instance.
295 * In case if you want to re-initialize lightGallery right after destroying it, initialize it only once the destroy process is completed.
296 * You can use refresh method most of the times.
297 * @category lGPublicMethods
298 * @example
299 * const plugin = lightGallery();
300 * plugin.destroy();
301 *
302 */
303 destroy(): number;
304}