1/*! lg-share - v1.0.2 - 2016-11-26 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(['jquery'], function (a0) { 9 return (factory(a0)); 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(require('jquery')); 16 } else { 17 factory(jQuery); 18 } 19}(this, function ($) { 20 21(function() { 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 if (this.core.s.share) { 43 this.init(); 44 } 45 46 return this; 47 }; 48 49 Share.prototype.init = function() { 50 var _this = this; 51 var shareHtml = '<span id="lg-share" class="lg-icon">' + 52 '<ul class="lg-dropdown" style="position: absolute;">'; 53 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>' : ''; 54 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>' : ''; 55 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>' : ''; 56 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>' : ''; 57 shareHtml += '</ul></span>'; 58 59 this.core.$outer.find('.lg-toolbar').append(shareHtml); 60 this.core.$outer.find('.lg').append('<div id="lg-dropdown-overlay"></div>'); 61 $('#lg-share').on('click.lg', function(){ 62 _this.core.$outer.toggleClass('lg-dropdown-active'); 63 }); 64 65 $('#lg-dropdown-overlay').on('click.lg', function(){ 66 _this.core.$outer.removeClass('lg-dropdown-active'); 67 }); 68 69 _this.core.$el.on('onAfterSlide.lg.tm', function(event, prevIndex, index) { 70 71 setTimeout(function() { 72 $('#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))); 73 74 $('#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))); 75 76 $('#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))); 77 78 $('#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')); 79 80 }, 100); 81 }); 82 }; 83 84 Share.prototype.destroy = function() { 85 86 }; 87 88 $.fn.lightGallery.modules.share = Share; 89 90})(); 91 92 93 94})); 95