lg-comment.es5.js 7.9 KB

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