Просмотр файла wu-static/js/lightgallery/js/lg-share.js

Размер файла: 4.02Kb
  1. /*! lg-share - v1.0.0 - 2016-09-20
  2. * http://sachinchoolur.github.io/lightGallery
  3. * Copyright (c) 2016 Sachin N; Licensed GPLv3 */
  4.  
  5. (function (root, factory) {
  6. if (typeof define === 'function' && define.amd) {
  7. // AMD. Register as an anonymous module unless amdModuleId is set
  8. define([], function () {
  9. return (factory());
  10. });
  11. } else if (typeof exports === 'object') {
  12. // Node. Does not work with strict CommonJS, but
  13. // only CommonJS-like environments that support module.exports,
  14. // like Node.
  15. module.exports = factory();
  16. } else {
  17. factory();
  18. }
  19. }(this, function () {
  20.  
  21. (function($, window, document, undefined) {
  22.  
  23. 'use strict';
  24.  
  25. var defaults = {
  26. share: true,
  27. facebook: true,
  28. facebookDropdownText: 'Facebook',
  29. twitter: true,
  30. twitterDropdownText: 'Twitter',
  31. googlePlus: true,
  32. googlePlusDropdownText: 'GooglePlus',
  33. pinterest: true,
  34. pinterestDropdownText: 'Pinterest'
  35. };
  36.  
  37. var Share = function(element) {
  38.  
  39. this.core = $(element).data('lightGallery');
  40.  
  41. this.core.s = $.extend({}, defaults, this.core.s);
  42. this.init();
  43.  
  44. return this;
  45. };
  46.  
  47. Share.prototype.init = function() {
  48. var _this = this;
  49. var shareHtml = '<span id="lg-share" class="lg-icon">' +
  50. '<ul class="lg-dropdown" style="position: absolute;">';
  51. shareHtml += _this.core.s.facebook ? '<li><a id="lg-share-facebook" target="_blank"><span class="lg-icon"></span><span class="lg-dropdown-text">' + this.core.s.facebookDropdownText + '</span></a></li>' : '';
  52. shareHtml += _this.core.s.twitter ? '<li><a id="lg-share-twitter" target="_blank"><span class="lg-icon"></span><span class="lg-dropdown-text">' + this.core.s.twitterDropdownText + '</span></a></li>' : '';
  53. shareHtml += _this.core.s.googlePlus ? '<li><a id="lg-share-googleplus" target="_blank"><span class="lg-icon"></span><span class="lg-dropdown-text">' + this.core.s.googlePlusDropdownText + '</span></a></li>' : '';
  54. shareHtml += _this.core.s.pinterest ? '<li><a id="lg-share-pinterest" target="_blank"><span class="lg-icon"></span><span class="lg-dropdown-text">' + this.core.s.pinterestDropdownText + '</span></a></li>' : '';
  55. shareHtml += '</ul></span>';
  56.  
  57. this.core.$outer.find('.lg-toolbar').append(shareHtml);
  58. this.core.$outer.find('.lg').append('<div id="lg-dropdown-overlay"></div>');
  59. $('#lg-share').on('click.lg', function(){
  60. _this.core.$outer.toggleClass('lg-dropdown-active');
  61. });
  62.  
  63. $('#lg-dropdown-overlay').on('click.lg', function(){
  64. _this.core.$outer.removeClass('lg-dropdown-active');
  65. });
  66.  
  67. _this.core.$el.on('onAfterSlide.lg.tm', function(event, prevIndex, index) {
  68.  
  69. setTimeout(function() {
  70. $('#lg-share-facebook').attr('href', 'https://www.facebook.com/sharer/sharer.php?u=' + (encodeURIComponent(_this.core.$items.eq(index).attr('data-facebook-share-url') || window.location.href)));
  71.  
  72. $('#lg-share-twitter').attr('href', 'https://twitter.com/intent/tweet?text=' + _this.core.$items.eq(index).attr('data-tweet-text') + '&url=' + (encodeURIComponent(_this.core.$items.eq(index).attr('data-twitter-share-url') || window.location.href)));
  73.  
  74. $('#lg-share-googleplus').attr('href', 'https://plus.google.com/share?url=' + (encodeURIComponent(_this.core.$items.eq(index).attr('data-googleplus-share-url') || window.location.href)));
  75.  
  76. $('#lg-share-pinterest').attr('href', 'http://www.pinterest.com/pin/create/button/?url=' + (encodeURIComponent(_this.core.$items.eq(index).attr('data-pinterest-share-url') || window.location.href)) + '&media=' + encodeURIComponent(_this.core.$items.eq(index).attr('href') || _this.core.$items.eq(index).attr('data-src')) + '&description=' + _this.core.$items.eq(index).attr('data-pinterest-text'));
  77.  
  78. }, 100);
  79. });
  80. };
  81.  
  82. Share.prototype.destroy = function() {
  83.  
  84. };
  85.  
  86. $.fn.lightGallery.modules.share = Share;
  87.  
  88. })(jQuery, window, document);
  89.  
  90.  
  91.  
  92. }));