lg-comment.umd.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*!
  2. * lightgallery | 2.4.0-beta.0 | December 12th 2021
  3. * http://www.lightgalleryjs.com/
  4. * Copyright (c) 2020 Sachin Neravath;
  5. * @license GPLv3
  6. */
  7. (function (global, factory) {
  8. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  9. typeof define === 'function' && define.amd ? define(factory) :
  10. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.lgComment = factory());
  11. }(this, (function () { 'use strict';
  12. /*! *****************************************************************************
  13. Copyright (c) Microsoft Corporation.
  14. Permission to use, copy, modify, and/or distribute this software for any
  15. purpose with or without fee is hereby granted.
  16. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
  17. REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  18. AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
  19. INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  20. LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  21. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  22. PERFORMANCE OF THIS SOFTWARE.
  23. ***************************************************************************** */
  24. var __assign = function() {
  25. __assign = Object.assign || function __assign(t) {
  26. for (var s, i = 1, n = arguments.length; i < n; i++) {
  27. s = arguments[i];
  28. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  29. }
  30. return t;
  31. };
  32. return __assign.apply(this, arguments);
  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. * */
  39. var 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. var commentSettings = {
  68. commentBox: false,
  69. fbComments: false,
  70. disqusComments: false,
  71. disqusConfig: {
  72. title: undefined,
  73. language: 'en',
  74. },
  75. 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>',
  76. commentPluginStrings: { toggleComments: 'Toggle Comments' },
  77. };
  78. /**
  79. * lightGallery comments module
  80. * Supports facebook and disqus comments
  81. *
  82. * @ref - https://help.disqus.com/customer/portal/articles/472098-javascript-configuration-variables
  83. * @ref - https://github.com/disqus/DISQUS-API-Recipes/blob/master/snippets/js/disqus-reset/disqus_reset.html
  84. * @ref - https://css-tricks.com/lazy-loading-disqus-comments/
  85. * @ref - https://developers.facebook.com/docs/plugins/comments/#comments-plugin
  86. *
  87. */
  88. var CommentBox = /** @class */ (function () {
  89. function CommentBox(instance, $LG) {
  90. // get lightGallery core plugin instance
  91. this.core = instance;
  92. this.$LG = $LG;
  93. // extend module default settings with lightGallery core settings
  94. this.settings = __assign(__assign({}, commentSettings), this.core.settings);
  95. return this;
  96. }
  97. CommentBox.prototype.init = function () {
  98. if (!this.settings.commentBox) {
  99. return;
  100. }
  101. this.setMarkup();
  102. this.toggleCommentBox();
  103. if (this.settings.fbComments) {
  104. this.addFbComments();
  105. }
  106. else if (this.settings.disqusComments) {
  107. this.addDisqusComments();
  108. }
  109. };
  110. CommentBox.prototype.setMarkup = function () {
  111. this.core.outer.append(this.settings.commentsMarkup +
  112. '<div class="lg-comment-overlay"></div>');
  113. var commentToggleBtn = "<button type=\"button\" aria-label=\"" + this.settings.commentPluginStrings['toggleComments'] + "\" class=\"lg-comment-toggle lg-icon\"></button>";
  114. this.core.$toolbar.append(commentToggleBtn);
  115. };
  116. CommentBox.prototype.toggleCommentBox = function () {
  117. var _this_1 = this;
  118. this.core.outer
  119. .find('.lg-comment-toggle')
  120. .first()
  121. .on('click.lg.comment', function () {
  122. _this_1.core.outer.toggleClass('lg-comment-active');
  123. });
  124. this.core.outer
  125. .find('.lg-comment-overlay')
  126. .first()
  127. .on('click.lg.comment', function () {
  128. _this_1.core.outer.removeClass('lg-comment-active');
  129. });
  130. this.core.outer
  131. .find('.lg-comment-close')
  132. .first()
  133. .on('click.lg.comment', function () {
  134. _this_1.core.outer.removeClass('lg-comment-active');
  135. });
  136. };
  137. CommentBox.prototype.addFbComments = function () {
  138. var _this_1 = this;
  139. // eslint-disable-next-line @typescript-eslint/no-this-alias
  140. var _this = this;
  141. this.core.LGel.on(lGEvents.beforeSlide + ".comment", function (event) {
  142. var html = _this_1.core.galleryItems[event.detail.index].fbHtml;
  143. _this_1.core.outer.find('.lg-comment-body').html(html);
  144. });
  145. this.core.LGel.on(lGEvents.afterSlide + ".comment", function () {
  146. try {
  147. FB.XFBML.parse();
  148. }
  149. catch (err) {
  150. _this.$LG(window).on('fbAsyncInit', function () {
  151. FB.XFBML.parse();
  152. });
  153. }
  154. });
  155. };
  156. CommentBox.prototype.addDisqusComments = function () {
  157. var _this_1 = this;
  158. var $disqusThread = this.$LG('#disqus_thread');
  159. $disqusThread.remove();
  160. this.core.outer
  161. .find('.lg-comment-body')
  162. .append('<div id="disqus_thread"></div>');
  163. this.core.LGel.on(lGEvents.beforeSlide + ".comment", function () {
  164. $disqusThread.html('');
  165. });
  166. this.core.LGel.on(lGEvents.afterSlide + ".comment", function (event) {
  167. var index = event.detail.index;
  168. // eslint-disable-next-line @typescript-eslint/no-this-alias
  169. var _this = _this_1;
  170. // DISQUS needs sometime to intialize when lightGallery is opened from direct url(hash plugin).
  171. setTimeout(function () {
  172. try {
  173. DISQUS.reset({
  174. reload: true,
  175. config: function () {
  176. this.page.identifier =
  177. _this.core.galleryItems[index].disqusIdentifier;
  178. this.page.url =
  179. _this.core.galleryItems[index].disqusURL;
  180. this.page.title =
  181. _this.settings.disqusConfig.title;
  182. this.language =
  183. _this.settings.disqusConfig.language;
  184. },
  185. });
  186. }
  187. catch (err) {
  188. console.error('Make sure you have included disqus JavaScript code in your document. Ex - https://lg-disqus.disqus.com/admin/install/platforms/universalcode/');
  189. }
  190. }, _this.core.lGalleryOn ? 0 : 1000);
  191. });
  192. };
  193. CommentBox.prototype.destroy = function () {
  194. this.core.LGel.off('.lg.comment');
  195. this.core.LGel.off('.comment');
  196. };
  197. return CommentBox;
  198. }());
  199. return CommentBox;
  200. })));
  201. //# sourceMappingURL=lg-comment.umd.js.map