UNPKG

8.98 kBJavaScriptView Raw
1/*!
2 * lightgallery | 2.2.1 | September 4th 2021
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 };
70
71 var commentSettings = {
72 commentBox: false,
73 fbComments: false,
74 disqusComments: false,
75 disqusConfig: {
76 title: undefined,
77 language: 'en',
78 },
79 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>',
80 };
81
82 /**
83 * lightGallery comments module
84 * Supports facebook and disqus comments
85 *
86 * @ref - https://help.disqus.com/customer/portal/articles/472098-javascript-configuration-variables
87 * @ref - https://github.com/disqus/DISQUS-API-Recipes/blob/master/snippets/js/disqus-reset/disqus_reset.html
88 * @ref - https://css-tricks.com/lazy-loading-disqus-comments/
89 * @ref - https://developers.facebook.com/docs/plugins/comments/#comments-plugin
90 *
91 */
92 var CommentBox = /** @class */ (function () {
93 function CommentBox(instance, $LG) {
94 // get lightGallery core plugin instance
95 this.core = instance;
96 this.$LG = $LG;
97 // extend module default settings with lightGallery core settings
98 this.settings = __assign(__assign({}, commentSettings), this.core.settings);
99 return this;
100 }
101 CommentBox.prototype.init = function () {
102 if (!this.settings.commentBox) {
103 return;
104 }
105 this.setMarkup();
106 this.toggleCommentBox();
107 if (this.settings.fbComments) {
108 this.addFbComments();
109 }
110 else if (this.settings.disqusComments) {
111 this.addDisqusComments();
112 }
113 };
114 CommentBox.prototype.setMarkup = function () {
115 this.core.outer.append(this.settings.commentsMarkup +
116 '<div class="lg-comment-overlay"></div>');
117 var commentToggleBtn = '<button type="button" aria-label="Toggle comments" class="lg-comment-toggle lg-icon"></button>';
118 this.core.$toolbar.append(commentToggleBtn);
119 };
120 CommentBox.prototype.toggleCommentBox = function () {
121 var _this_1 = this;
122 this.core.outer
123 .find('.lg-comment-toggle')
124 .first()
125 .on('click.lg.comment', function () {
126 _this_1.core.outer.toggleClass('lg-comment-active');
127 });
128 this.core.outer
129 .find('.lg-comment-overlay')
130 .first()
131 .on('click.lg.comment', function () {
132 _this_1.core.outer.removeClass('lg-comment-active');
133 });
134 this.core.outer
135 .find('.lg-comment-close')
136 .first()
137 .on('click.lg.comment', function () {
138 _this_1.core.outer.removeClass('lg-comment-active');
139 });
140 };
141 CommentBox.prototype.addFbComments = function () {
142 var _this_1 = this;
143 // eslint-disable-next-line @typescript-eslint/no-this-alias
144 var _this = this;
145 this.core.LGel.on(lGEvents.beforeSlide + ".comment", function (event) {
146 var html = _this_1.core.galleryItems[event.detail.index].fbHtml;
147 _this_1.core.outer.find('.lg-comment-body').html(html);
148 });
149 this.core.LGel.on(lGEvents.afterSlide + ".comment", function () {
150 try {
151 FB.XFBML.parse();
152 }
153 catch (err) {
154 _this.$LG(window).on('fbAsyncInit', function () {
155 FB.XFBML.parse();
156 });
157 }
158 });
159 };
160 CommentBox.prototype.addDisqusComments = function () {
161 var _this_1 = this;
162 var $disqusThread = this.$LG('#disqus_thread');
163 $disqusThread.remove();
164 this.core.outer
165 .find('.lg-comment-body')
166 .append('<div id="disqus_thread"></div>');
167 this.core.LGel.on(lGEvents.beforeSlide + ".comment", function () {
168 $disqusThread.html('');
169 });
170 this.core.LGel.on(lGEvents.afterSlide + ".comment", function (event) {
171 var index = event.detail.index;
172 // eslint-disable-next-line @typescript-eslint/no-this-alias
173 var _this = _this_1;
174 // DISQUS needs sometime to intialize when lightGallery is opened from direct url(hash plugin).
175 setTimeout(function () {
176 try {
177 DISQUS.reset({
178 reload: true,
179 config: function () {
180 this.page.identifier =
181 _this.core.galleryItems[index].disqusIdentifier;
182 this.page.url =
183 _this.core.galleryItems[index].disqusURL;
184 this.page.title =
185 _this.settings.disqusConfig.title;
186 this.language =
187 _this.settings.disqusConfig.language;
188 },
189 });
190 }
191 catch (err) {
192 console.error('Make sure you have included disqus JavaScript code in your document. Ex - https://lg-disqus.disqus.com/admin/install/platforms/universalcode/');
193 }
194 }, _this.core.lGalleryOn ? 0 : 1000);
195 });
196 };
197 CommentBox.prototype.destroy = function () {
198 this.core.LGel.off('.lg.comment');
199 this.core.LGel.off('.comment');
200 };
201 return CommentBox;
202 }());
203
204 return CommentBox;
205
206})));
207//# sourceMappingURL=lg-comment.umd.js.map