UNPKG

9.24 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(function (global, factory) {
9 typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
10 typeof define === 'function' && define.amd ? define(factory) :
11 (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.lgComment = factory());
12}(this, (function () { 'use strict';
13
14 /*! *****************************************************************************
15 Copyright (c) Microsoft Corporation.
16
17 Permission to use, copy, modify, and/or distribute this software for any
18 purpose with or without fee is hereby granted.
19
20 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
21 REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
22 AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
23 INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
24 LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
25 OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
26 PERFORMANCE OF THIS SOFTWARE.
27 ***************************************************************************** */
28
29 var __assign = function() {
30 __assign = Object.assign || function __assign(t) {
31 for (var s, i = 1, n = arguments.length; i < n; i++) {
32 s = arguments[i];
33 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
34 }
35 return t;
36 };
37 return __assign.apply(this, arguments);
38 };
39
40 /**
41 * List of lightGallery events
42 * All events should be documented here
43 * Below interfaces are used to build the website documentations
44 * */
45 var lGEvents = {
46 afterAppendSlide: 'lgAfterAppendSlide',
47 init: 'lgInit',
48 hasVideo: 'lgHasVideo',
49 containerResize: 'lgContainerResize',
50 updateSlides: 'lgUpdateSlides',
51 afterAppendSubHtml: 'lgAfterAppendSubHtml',
52 beforeOpen: 'lgBeforeOpen',
53 afterOpen: 'lgAfterOpen',
54 slideItemLoad: 'lgSlideItemLoad',
55 beforeSlide: 'lgBeforeSlide',
56 afterSlide: 'lgAfterSlide',
57 posterClick: 'lgPosterClick',
58 dragStart: 'lgDragStart',
59 dragMove: 'lgDragMove',
60 dragEnd: 'lgDragEnd',
61 beforeNextSlide: 'lgBeforeNextSlide',
62 beforePrevSlide: 'lgBeforePrevSlide',
63 beforeClose: 'lgBeforeClose',
64 afterClose: 'lgAfterClose',
65 rotateLeft: 'lgRotateLeft',
66 rotateRight: 'lgRotateRight',
67 flipHorizontal: 'lgFlipHorizontal',
68 flipVertical: 'lgFlipVertical',
69 autoplay: 'lgAutoplay',
70 autoplayStart: 'lgAutoplayStart',
71 autoplayStop: 'lgAutoplayStop',
72 };
73
74 var commentSettings = {
75 commentBox: false,
76 fbComments: false,
77 disqusComments: false,
78 disqusConfig: {
79 title: undefined,
80 language: 'en',
81 },
82 commentsMarkup: '<div id="lg-comment-box" class="lg-comment-box lg-fb-comment-box"><div class="lg-comment-header"><h3 class="lg-comment-title">Leave a comment.</h3><span class="lg-comment-close lg-icon"></span></div><div class="lg-comment-body"></div></div>',
83 commentPluginStrings: {
84 toggleComments: 'Toggle Comments',
85 },
86 };
87
88 /**
89 * lightGallery comments module
90 * Supports facebook and disqus comments
91 *
92 * @ref - https://help.disqus.com/customer/portal/articles/472098-javascript-configuration-variables
93 * @ref - https://github.com/disqus/DISQUS-API-Recipes/blob/master/snippets/js/disqus-reset/disqus_reset.html
94 * @ref - https://css-tricks.com/lazy-loading-disqus-comments/
95 * @ref - https://developers.facebook.com/docs/plugins/comments/#comments-plugin
96 *
97 */
98 var CommentBox = /** @class */ (function () {
99 function CommentBox(instance, $LG) {
100 // get lightGallery core plugin instance
101 this.core = instance;
102 this.$LG = $LG;
103 // extend module default settings with lightGallery core settings
104 this.settings = __assign(__assign({}, commentSettings), this.core.settings);
105 return this;
106 }
107 CommentBox.prototype.init = function () {
108 if (!this.settings.commentBox) {
109 return;
110 }
111 this.setMarkup();
112 this.toggleCommentBox();
113 if (this.settings.fbComments) {
114 this.addFbComments();
115 }
116 else if (this.settings.disqusComments) {
117 this.addDisqusComments();
118 }
119 };
120 CommentBox.prototype.setMarkup = function () {
121 this.core.outer.append(this.settings.commentsMarkup +
122 '<div class="lg-comment-overlay"></div>');
123 var commentToggleBtn = "<button type=\"button\" aria-label=\"" + this.settings.commentPluginStrings['toggleComments'] + "\" class=\"lg-comment-toggle lg-icon\"></button>";
124 this.core.$toolbar.append(commentToggleBtn);
125 };
126 CommentBox.prototype.toggleCommentBox = function () {
127 var _this_1 = this;
128 this.core.outer
129 .find('.lg-comment-toggle')
130 .first()
131 .on('click.lg.comment', function () {
132 _this_1.core.outer.toggleClass('lg-comment-active');
133 });
134 this.core.outer
135 .find('.lg-comment-overlay')
136 .first()
137 .on('click.lg.comment', function () {
138 _this_1.core.outer.removeClass('lg-comment-active');
139 });
140 this.core.outer
141 .find('.lg-comment-close')
142 .first()
143 .on('click.lg.comment', function () {
144 _this_1.core.outer.removeClass('lg-comment-active');
145 });
146 };
147 CommentBox.prototype.addFbComments = function () {
148 var _this_1 = this;
149 // eslint-disable-next-line @typescript-eslint/no-this-alias
150 var _this = this;
151 this.core.LGel.on(lGEvents.beforeSlide + ".comment", function (event) {
152 var html = _this_1.core.galleryItems[event.detail.index].fbHtml;
153 _this_1.core.outer.find('.lg-comment-body').html(html);
154 });
155 this.core.LGel.on(lGEvents.afterSlide + ".comment", function () {
156 try {
157 FB.XFBML.parse();
158 }
159 catch (err) {
160 _this.$LG(window).on('fbAsyncInit', function () {
161 FB.XFBML.parse();
162 });
163 }
164 });
165 };
166 CommentBox.prototype.addDisqusComments = function () {
167 var _this_1 = this;
168 var $disqusThread = this.$LG('#disqus_thread');
169 $disqusThread.remove();
170 this.core.outer
171 .find('.lg-comment-body')
172 .append('<div id="disqus_thread"></div>');
173 this.core.LGel.on(lGEvents.beforeSlide + ".comment", function () {
174 $disqusThread.html('');
175 });
176 this.core.LGel.on(lGEvents.afterSlide + ".comment", function (event) {
177 var index = event.detail.index;
178 // eslint-disable-next-line @typescript-eslint/no-this-alias
179 var _this = _this_1;
180 // DISQUS needs sometime to intialize when lightGallery is opened from direct url(hash plugin).
181 setTimeout(function () {
182 try {
183 DISQUS.reset({
184 reload: true,
185 config: function () {
186 this.page.identifier =
187 _this.core.galleryItems[index].disqusIdentifier;
188 this.page.url =
189 _this.core.galleryItems[index].disqusURL;
190 this.page.title =
191 _this.settings.disqusConfig.title;
192 this.language =
193 _this.settings.disqusConfig.language;
194 },
195 });
196 }
197 catch (err) {
198 console.error('Make sure you have included disqus JavaScript code in your document. Ex - https://lg-disqus.disqus.com/admin/install/platforms/universalcode/');
199 }
200 }, _this.core.lGalleryOn ? 0 : 1000);
201 });
202 };
203 CommentBox.prototype.destroy = function () {
204 this.core.LGel.off('.lg.comment');
205 this.core.LGel.off('.comment');
206 };
207 return CommentBox;
208 }());
209
210 return CommentBox;
211
212})));
213//# sourceMappingURL=lg-comment.umd.js.map