Skip to content

Commit

Permalink
Upgrade share plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
sachinchoolur committed Jan 14, 2018
1 parent 1d8f126 commit 37b103e
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 14 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lightgallery.js",
"version": "1.0.0",
"version": "1.0.2",
"description": "Full featured lightbox gallery. Zero dependencies",
"main": [
"dist/js/lightgallery.min.js",
Expand Down
45 changes: 37 additions & 8 deletions demo/js/lg-share.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**!
* lg-share.js | 1.0.0 | October 5th 2016
* lg-share.js | 1.2.0 | January 14th 2018
* http://sachinchoolur.github.io/lg-share.js
* Copyright (c) 2016 Sachin N;
* @license GPLv3
Expand Down Expand Up @@ -45,6 +45,12 @@
pinterestDropdownText: 'Pinterest'
};

function toCamelCase(input) {
return input.toLowerCase().replace(/-(.)/g, function (match, group1) {
return group1.toUpperCase();
});
}

var Share = function Share(element) {

this.el = element;
Expand Down Expand Up @@ -85,17 +91,40 @@
utils.on(_this.core.el, 'onAfterSlide.lgtm', function (event) {

setTimeout(function () {
document.getElementById('lg-share-facebook').setAttribute('href', 'https://www.facebook.com/sharer/sharer.php?u=' + encodeURIComponent(_this.core.items[event.detail.index].getAttribute('data-facebook-share-url') || window.location.href));

document.getElementById('lg-share-twitter').setAttribute('href', 'https://twitter.com/intent/tweet?text=' + _this.core.items[event.detail.index].getAttribute('data-tweet-text') + '&url=' + encodeURIComponent(_this.core.items[event.detail.index].getAttribute('data-twitter-share-url') || window.location.href));

document.getElementById('lg-share-googleplus').setAttribute('href', 'https://plus.google.com/share?url=' + encodeURIComponent(_this.core.items[event.detail.index].getAttribute('data-googleplus-share-url') || window.location.href));

document.getElementById('lg-share-pinterest').setAttribute('href', 'http://www.pinterest.com/pin/create/button/?url=' + encodeURIComponent(_this.core.items[event.detail.index].getAttribute('data-pinterest-share-url') || window.location.href) + '&media=' + encodeURIComponent(_this.core.items[event.detail.index].getAttribute('href') || _this.core.items[event.detail.index].getAttribute('data-src')) + '&description=' + _this.core.items[event.detail.index].getAttribute('data-pinterest-text'));
if (_this.core.s.facebook) {
document.getElementById('lg-share-facebook').setAttribute('href', 'https://www.facebook.com/sharer/sharer.php?u=' + _this.getSharePropsUrl(event.detail.index, 'data-facebook-share-url'));
}
if (_this.core.s.twitter) {
document.getElementById('lg-share-twitter').setAttribute('href', 'https://twitter.com/intent/tweet?text=' + _this.getShareProps(event.detail.index, 'data-tweet-text') + '&url=' + _this.getSharePropsUrl(event.detail.index, 'data-twitter-share-url'));
}
if (_this.core.s.googlePlus) {
document.getElementById('lg-share-googleplus').setAttribute('href', 'https://plus.google.com/share?url=' + _this.getSharePropsUrl(event.detail.index, 'data-googleplus-share-url'));
}
if (_this.core.s.pinterest) {
document.getElementById('lg-share-pinterest').setAttribute('href', 'http://www.pinterest.com/pin/create/button/?url=' + _this.getSharePropsUrl(event.detail.index, 'data-pinterest-share-url') + '&media=' + encodeURIComponent(_this.getShareProps(event.detail.index, 'href') || _this.getShareProps(event.detail.index, 'data-src')) + '&description=' + _this.getShareProps(event.detail.index, 'data-pinterest-text'));
}
}, 100);
});
};

Share.prototype.getSharePropsUrl = function (index, prop) {
var shareProp = this.getShareProps(index, prop);
if (!shareProp) {
shareProp = window.location.href;
}
return encodeURIComponent(shareProp);
};

Share.prototype.getShareProps = function (index, prop) {
var shareProp = '';
if (this.core.s.dynamic) {
shareProp = this.core.items[index][toCamelCase(prop.replace('data-', ''))];
} else if (this.core.items[index].getAttribute(prop)) {
shareProp = this.core.items[index].getAttribute(prop);
}
return shareProp;
};

Share.prototype.destroy = function () {};

window.lgModules.share = Share;
Expand Down
4 changes: 2 additions & 2 deletions demo/js/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 dist/js/lightgallery.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**!
* lightgallery.js | 1.0.1 | December 22nd 2016
* lightgallery.js | 1.0.2 | January 14th 2018
* http://sachinchoolur.github.io/lightgallery.js/
* Copyright (c) 2016 Sachin N;
* @license GPLv3
Expand Down
2 changes: 1 addition & 1 deletion dist/js/lightgallery.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": "lightgallery.js",
"version": "1.0.1",
"version": "1.0.2",
"description": "Full featured lightbox gallery. Zero dependencies",
"keywords": [
"gallery",
Expand Down

0 comments on commit 37b103e

Please sign in to comment.