lg-share.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /**!
  2. * lg-share.js | 0.0.1 | August 1st 2016
  3. * http://sachinchoolur.github.io/lg-share.js
  4. * Copyright (c) 2016 Sachin N;
  5. * @license Apache 2.0
  6. */(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.LgShare = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  7. (function (global, factory) {
  8. if (typeof define === "function" && define.amd) {
  9. define([], factory);
  10. } else if (typeof exports !== "undefined") {
  11. factory();
  12. } else {
  13. var mod = {
  14. exports: {}
  15. };
  16. factory();
  17. global.lgShare = mod.exports;
  18. }
  19. })(this, function () {
  20. 'use strict';
  21. var _extends = Object.assign || function (target) {
  22. for (var i = 1; i < arguments.length; i++) {
  23. var source = arguments[i];
  24. for (var key in source) {
  25. if (Object.prototype.hasOwnProperty.call(source, key)) {
  26. target[key] = source[key];
  27. }
  28. }
  29. }
  30. return target;
  31. };
  32. var shareSefaults = {
  33. share: true,
  34. facebook: true,
  35. facebookDropdownText: 'Facebook',
  36. twitter: true,
  37. twitterDropdownText: 'Twitter',
  38. googlePlus: true,
  39. googlePlusDropdownText: 'GooglePlus',
  40. pinterest: true,
  41. pinterestDropdownText: 'Pinterest'
  42. };
  43. var Share = function Share(element) {
  44. this.el = element;
  45. this.core = window.lgData[this.el.getAttribute('lg-uid')];
  46. this.core.s = _extends({}, shareSefaults, this.core.s);
  47. if (this.core.s.share) {
  48. this.init();
  49. }
  50. return this;
  51. };
  52. Share.prototype.init = function () {
  53. var _this = this;
  54. var shareHtml = '<span id="lg-share" class="lg-icon">' + '<ul class="lg-dropdown" style="position: absolute;">';
  55. 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>' : '';
  56. 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>' : '';
  57. 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>' : '';
  58. 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>' : '';
  59. shareHtml += '</ul></span>';
  60. this.core.outer.querySelector('.lg-toolbar').insertAdjacentHTML('beforeend', shareHtml);
  61. this.core.outer.querySelector('.lg').insertAdjacentHTML('beforeend', '<div id="lg-dropdown-overlay"></div>');
  62. utils.on(document.getElementById('lg-share'), 'click.lg', function () {
  63. if (utils.hasClass(_this.core.outer, 'lg-dropdown-active')) {
  64. utils.removeClass(_this.core.outer, 'lg-dropdown-active');
  65. } else {
  66. utils.addClass(_this.core.outer, 'lg-dropdown-active');
  67. }
  68. });
  69. utils.on(document.getElementById('lg-dropdown-overlay'), 'click.lg', function () {
  70. utils.removeClass(_this.core.outer, 'lg-dropdown-active');
  71. });
  72. utils.on(_this.core.el, 'onAfterSlide.lgtm', function (event) {
  73. setTimeout(function () {
  74. 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));
  75. 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));
  76. 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));
  77. 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'));
  78. }, 100);
  79. });
  80. };
  81. Share.prototype.destroy = function () {};
  82. window.lgModules.share = Share;
  83. });
  84. },{}]},{},[1])(1)
  85. });