Skip to content

Commit

Permalink
Introduce sharing for dynamic mode..
Browse files Browse the repository at this point in the history
  • Loading branch information
sachinchoolur committed Oct 3, 2017
1 parent 782ebca commit b25acec
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 17 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lg-share",
"version": "1.0.2",
"version": "1.1.0",
"description": "Social media share module for lightgallery.",
"main": [
"dist/lg-share.min.js"
Expand Down
27 changes: 20 additions & 7 deletions dist/lg-share.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*! lg-share - v1.0.2 - 2016-11-26
/*! lg-share - v1.1.0 - 2017-10-03
* http://sachinchoolur.github.io/lightGallery
* Copyright (c) 2016 Sachin N; Licensed GPLv3 */
* Copyright (c) 2017 Sachin N; Licensed GPLv3 */

(function (root, factory) {
if (typeof define === 'function' && define.amd) {
Expand Down Expand Up @@ -68,19 +68,32 @@

_this.core.$el.on('onAfterSlide.lg.tm', function(event, prevIndex, index) {

setTimeout(function() {
$('#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)));
setTimeout(function() {

$('#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)));
$('#lg-share-facebook').attr('href', 'https://www.facebook.com/sharer/sharer.php?u=' + (encodeURIComponent(_this.getSahreProps(index, 'facebookShareUrl') || window.location.href)));

$('#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)));
$('#lg-share-twitter').attr('href', 'https://twitter.com/intent/tweet?text=' + _this.getSahreProps(index, 'tweetText') + '&url=' + (encodeURIComponent(_this.getSahreProps(index, 'twitterShareUrl') || window.location.href)));

$('#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'));
$('#lg-share-googleplus').attr('href', 'https://plus.google.com/share?url=' + (encodeURIComponent(_this.getSahreProps(index, 'googleplusShareUrl') || window.location.href)));

$('#lg-share-pinterest').attr('href', 'http://www.pinterest.com/pin/create/button/?url=' + (encodeURIComponent(_this.getSahreProps(index, 'pinterestShareUrl') || window.location.href)) + '&media=' + encodeURIComponent(_this.getSahreProps(index, 'src')) + '&description=' + _this.getSahreProps(index, 'pinterestText'));

}, 100);
});
};

Share.prototype.getSahreProps = function(index, prop){
var shareProp = '';
if(this.core.s.dynamic) {
shareProp = this.core.s.dynamicEl[index][prop];
} else {
var _href = this.core.$items.eq(index).attr('href');
var _prop = this.core.$items.eq(index).data(prop);
shareProp = prop === 'src' ? _href || _prop : _prop;
}
return shareProp;
};

Share.prototype.destroy = function() {

};
Expand Down
6 changes: 3 additions & 3 deletions dist/lg-share.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lg-share",
"version": "1.0.2",
"version": "1.1.0",
"description": "Social media share module for lightgallery.",
"keywords": [
"gallery",
Expand Down
23 changes: 18 additions & 5 deletions src/lg-share.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,32 @@

_this.core.$el.on('onAfterSlide.lg.tm', function(event, prevIndex, index) {

setTimeout(function() {
$('#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)));
setTimeout(function() {

$('#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)));
$('#lg-share-facebook').attr('href', 'https://www.facebook.com/sharer/sharer.php?u=' + (encodeURIComponent(_this.getSahreProps(index, 'facebookShareUrl') || window.location.href)));

$('#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)));
$('#lg-share-twitter').attr('href', 'https://twitter.com/intent/tweet?text=' + _this.getSahreProps(index, 'tweetText') + '&url=' + (encodeURIComponent(_this.getSahreProps(index, 'twitterShareUrl') || window.location.href)));

$('#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'));
$('#lg-share-googleplus').attr('href', 'https://plus.google.com/share?url=' + (encodeURIComponent(_this.getSahreProps(index, 'googleplusShareUrl') || window.location.href)));

$('#lg-share-pinterest').attr('href', 'http://www.pinterest.com/pin/create/button/?url=' + (encodeURIComponent(_this.getSahreProps(index, 'pinterestShareUrl') || window.location.href)) + '&media=' + encodeURIComponent(_this.getSahreProps(index, 'src')) + '&description=' + _this.getSahreProps(index, 'pinterestText'));

}, 100);
});
};

Share.prototype.getSahreProps = function(index, prop){
var shareProp = '';
if(this.core.s.dynamic) {
shareProp = this.core.s.dynamicEl[index][prop];
} else {
var _href = this.core.$items.eq(index).attr('href');
var _prop = this.core.$items.eq(index).data(prop);
shareProp = prop === 'src' ? _href || _prop : _prop;
}
return shareProp;
};

Share.prototype.destroy = function() {

};
Expand Down

2 comments on commit b25acec

@pyronaur
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a typo at getSahreProps

@sachinchoolur
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks :)
I'll update it ASAP

Please sign in to comment.