UNPKG

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