UNPKG

8.03 kBJavaScriptView Raw
1/*!
2 * lightgallery | 2.7.1 | January 11th 2023
3 * http://www.lightgalleryjs.com/
4 * Copyright (c) 2020 Sachin Neravath;
5 * @license GPLv3
6 */
7
8/*! *****************************************************************************
9Copyright (c) Microsoft Corporation.
10
11Permission to use, copy, modify, and/or distribute this software for any
12purpose with or without fee is hereby granted.
13
14THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
15REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
16AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
17INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
18LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
19OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20PERFORMANCE OF THIS SOFTWARE.
21***************************************************************************** */
22
23var __assign = function() {
24 __assign = Object.assign || function __assign(t) {
25 for (var s, i = 1, n = arguments.length; i < n; i++) {
26 s = arguments[i];
27 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
28 }
29 return t;
30 };
31 return __assign.apply(this, arguments);
32};
33
34function __awaiter(thisArg, _arguments, P, generator) {
35 function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
36 return new (P || (P = Promise))(function (resolve, reject) {
37 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
38 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
39 function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
40 step((generator = generator.apply(thisArg, _arguments || [])).next());
41 });
42}
43
44function __generator(thisArg, body) {
45 var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
46 return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
47 function verb(n) { return function (v) { return step([n, v]); }; }
48 function step(op) {
49 if (f) throw new TypeError("Generator is already executing.");
50 while (_) try {
51 if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
52 if (y = 0, t) op = [op[0] & 2, t.value];
53 switch (op[0]) {
54 case 0: case 1: t = op; break;
55 case 4: _.label++; return { value: op[1], done: false };
56 case 5: _.label++; y = op[1]; op = [0]; continue;
57 case 7: op = _.ops.pop(); _.trys.pop(); continue;
58 default:
59 if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
60 if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
61 if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
62 if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
63 if (t[2]) _.ops.pop();
64 _.trys.pop(); continue;
65 }
66 op = body.call(thisArg, _);
67 } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
68 if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
69 }
70}
71
72/**
73 * List of lightGallery events
74 * All events should be documented here
75 * Below interfaces are used to build the website documentations
76 * */
77var lGEvents = {
78 afterAppendSlide: 'lgAfterAppendSlide',
79 init: 'lgInit',
80 hasVideo: 'lgHasVideo',
81 containerResize: 'lgContainerResize',
82 updateSlides: 'lgUpdateSlides',
83 afterAppendSubHtml: 'lgAfterAppendSubHtml',
84 beforeOpen: 'lgBeforeOpen',
85 afterOpen: 'lgAfterOpen',
86 slideItemLoad: 'lgSlideItemLoad',
87 beforeSlide: 'lgBeforeSlide',
88 afterSlide: 'lgAfterSlide',
89 posterClick: 'lgPosterClick',
90 dragStart: 'lgDragStart',
91 dragMove: 'lgDragMove',
92 dragEnd: 'lgDragEnd',
93 beforeNextSlide: 'lgBeforeNextSlide',
94 beforePrevSlide: 'lgBeforePrevSlide',
95 beforeClose: 'lgBeforeClose',
96 afterClose: 'lgAfterClose',
97 rotateLeft: 'lgRotateLeft',
98 rotateRight: 'lgRotateRight',
99 flipHorizontal: 'lgFlipHorizontal',
100 flipVertical: 'lgFlipVertical',
101 autoplay: 'lgAutoplay',
102 autoplayStart: 'lgAutoplayStart',
103 autoplayStop: 'lgAutoplayStop',
104};
105
106var vimeoSettings = {
107 showVimeoThumbnails: true,
108 showThumbnailWithPlayButton: false,
109};
110
111/**
112 * Creates the vimeo thumbnails plugin.
113 * @param {object} element - lightGallery element
114 */
115var VimeoThumbnail = /** @class */ (function () {
116 function VimeoThumbnail(instance) {
117 this.core = instance;
118 // extend module default settings with lightGallery core settings
119 this.settings = __assign(__assign({}, vimeoSettings), this.core.settings);
120 return this;
121 }
122 VimeoThumbnail.prototype.init = function () {
123 var _this = this;
124 if (!this.settings.showVimeoThumbnails) {
125 return;
126 }
127 this.core.LGel.on(lGEvents.init + ".vimeothumbnails", function (event) {
128 var pluginInstance = event.detail.instance;
129 var thumbCont = pluginInstance.$container
130 .find('.lg-thumb-outer')
131 .get();
132 if (thumbCont) {
133 _this.setVimeoThumbnails(pluginInstance);
134 }
135 });
136 };
137 VimeoThumbnail.prototype.setVimeoThumbnails = function (dynamicGallery) {
138 return __awaiter(this, void 0, void 0, function () {
139 var i, item, slideVideoInfo, response, vimeoInfo;
140 return __generator(this, function (_a) {
141 switch (_a.label) {
142 case 0:
143 i = 0;
144 _a.label = 1;
145 case 1:
146 if (!(i < dynamicGallery.galleryItems.length)) return [3 /*break*/, 5];
147 item = dynamicGallery.galleryItems[i];
148 slideVideoInfo = item.__slideVideoInfo || {};
149 if (!slideVideoInfo.vimeo) return [3 /*break*/, 4];
150 return [4 /*yield*/, fetch('https://vimeo.com/api/oembed.json?url=' +
151 encodeURIComponent(item.src))];
152 case 2:
153 response = _a.sent();
154 return [4 /*yield*/, response.json()];
155 case 3:
156 vimeoInfo = _a.sent();
157 dynamicGallery.$container
158 .find('.lg-thumb-item')
159 .eq(i)
160 .find('img')
161 .attr('src', this.settings.showThumbnailWithPlayButton
162 ? vimeoInfo.thumbnail_url_with_play_button
163 : vimeoInfo.thumbnail_url);
164 _a.label = 4;
165 case 4:
166 i++;
167 return [3 /*break*/, 1];
168 case 5: return [2 /*return*/];
169 }
170 });
171 });
172 };
173 VimeoThumbnail.prototype.destroy = function () {
174 // Remove all event listeners added by vimeothumbnails plugin
175 this.core.LGel.off('.lg.vimeothumbnails');
176 this.core.LGel.off('.vimeothumbnails');
177 };
178 return VimeoThumbnail;
179}());
180
181export default VimeoThumbnail;
182//# sourceMappingURL=lg-vimeo-thumbnail.es5.js.map