UNPKG

8.14 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
34/**
35 * List of lightGallery events
36 * All events should be documented here
37 * Below interfaces are used to build the website documentations
38 * */
39var lGEvents = {
40 afterAppendSlide: 'lgAfterAppendSlide',
41 init: 'lgInit',
42 hasVideo: 'lgHasVideo',
43 containerResize: 'lgContainerResize',
44 updateSlides: 'lgUpdateSlides',
45 afterAppendSubHtml: 'lgAfterAppendSubHtml',
46 beforeOpen: 'lgBeforeOpen',
47 afterOpen: 'lgAfterOpen',
48 slideItemLoad: 'lgSlideItemLoad',
49 beforeSlide: 'lgBeforeSlide',
50 afterSlide: 'lgAfterSlide',
51 posterClick: 'lgPosterClick',
52 dragStart: 'lgDragStart',
53 dragMove: 'lgDragMove',
54 dragEnd: 'lgDragEnd',
55 beforeNextSlide: 'lgBeforeNextSlide',
56 beforePrevSlide: 'lgBeforePrevSlide',
57 beforeClose: 'lgBeforeClose',
58 afterClose: 'lgAfterClose',
59 rotateLeft: 'lgRotateLeft',
60 rotateRight: 'lgRotateRight',
61 flipHorizontal: 'lgFlipHorizontal',
62 flipVertical: 'lgFlipVertical',
63 autoplay: 'lgAutoplay',
64 autoplayStart: 'lgAutoplayStart',
65 autoplayStop: 'lgAutoplayStop',
66};
67
68var commentSettings = {
69 commentBox: false,
70 fbComments: false,
71 disqusComments: false,
72 disqusConfig: {
73 title: undefined,
74 language: 'en',
75 },
76 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>',
77 commentPluginStrings: {
78 toggleComments: 'Toggle Comments',
79 },
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 */
92var 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=\"" + this.settings.commentPluginStrings['toggleComments'] + "\" 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
204export default CommentBox;
205//# sourceMappingURL=lg-comment.es5.js.map