1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
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 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
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 |
|
42 |
|
43 |
|
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 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 | var CommentBox = (function () {
|
99 | function CommentBox(instance, $LG) {
|
100 |
|
101 | this.core = instance;
|
102 | this.$LG = $LG;
|
103 |
|
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 |
|
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 |
|
179 | var _this = _this_1;
|
180 |
|
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 |
|