forked from koddr/goodshare.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
goodshare.min.js
37 lines (37 loc) · 18.5 KB
/
goodshare.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
'use strict';(function(){function g(c,b){if(!(c instanceof b))throw new TypeError("Cannot call a class as a function");}function v(c,b){for(var a=0;a<b.length;a++){var e=b[a];e.enumerable=e.enumerable||!1;e.configurable=!0;"value"in e&&(e.writable=!0);Object.defineProperty(c,e.key,e)}}function k(c,b,a){b&&v(c.prototype,b);a&&v(c,a);return c}function n(c,b){if("function"!==typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function");c.prototype=Object.create(b&&b.prototype,
{constructor:{value:c,writable:!0,configurable:!0}});b&&t(c,b)}function l(c){l=Object.setPrototypeOf?Object.getPrototypeOf:function(b){return b.__proto__||Object.getPrototypeOf(b)};return l(c)}function t(c,b){t=Object.setPrototypeOf||function(a,b){a.__proto__=b;return a};return t(c,b)}function m(c){if(void 0===c)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return c}function p(c,b){return!b||"object"!==typeof b&&"function"!==typeof b?m(c):b}function q(c){if(Array.isArray(c)){var b=
0;for(var a=Array(c.length);b<c.length;b++)a[b]=c[b];b=a}else b=void 0;b||(b=Symbol.iterator in Object(c)||"[object Arguments]"===Object.prototype.toString.call(c)?Array.from(c):void 0);if(!(c=b))throw new TypeError("Invalid attempt to spread non-iterable instance");return c}var w=function(){function c(){g(this,c);this.handlers={}}k(c,[{key:"addEventListener",value:function(){var b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:document,a=1<arguments.length&&void 0!==arguments[1]?arguments[1]:
"click";this.handlers[a]={func:2<arguments.length?arguments[2]:void 0,target:b};var e=a.split(".")[0];b.addEventListener(e,this.handlers[a].func)}},{key:"removeEventListener",value:function(){var b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"click",a=b.split(".")[0],e=this.handlers[b];e.target.removeEventListener(a,e.func);delete this.handlers[b]}},{key:"removeAll",value:function(){for(var b in this.handlers)this.removeEventListener(b)}}]);return c}(),x=function(){return"".concat(0<arguments.length&&
void 0!==arguments[0]?arguments[0]:"id","-").concat(Math.random().toString(36).substr(2,8))},h=function(){function c(){g(this,c);this.events=new w;this.callback=function(){};this.updateInstanceId()}k(c,[{key:"eventHandler",value:function(b,a){var e=this,d=a.share_url,c=a.windowTitle,r=a.windowWidth,g=a.windowHeight;a=a.useLocation;b.preventDefault();if(a)window.top.location=d;else{a=Math.round((window.outerHeight||window.document.documentElement.offsetHeight)/2-g/2);var k=Math.round((window.outerWidth||
window.document.documentElement.offsetWidth)/2-r/2);r="width=".concat(r,",height=").concat(g);g="left=".concat(k,",top=").concat(a);var l="".concat(r,",").concat(g,",location=no,toolbar=no,menubar=no"),h=window.open(d,c,l),m=setInterval(function(){h.closed&&(e.callback(b,{share_url:d,windowTitle:c,windowOptions:l},h),clearInterval(m))},10);return h}}},{key:"setShareCallback",value:function(b){this.callback=b}},{key:"createEvents",value:function(b){var a=this;q(b).forEach(function(b){var e=a.getPreparedData(b);
a.events.addEventListener(b,"click.".concat(a.instanceId),function(b){return a.eventHandler.call(a,b,e)})})}},{key:"getInstance",value:function(){"function"===typeof this.shareWindow&&this.shareWindow();"function"===typeof this.getCounter&&this.getCounter();return this}},{key:"updateInstanceId",value:function(){this.instanceId=x()}},{key:"reNewInstance",value:function(){this.events.removeAll();this.updateInstanceId();return this.getInstance()}}]);return c}(),u=function(c){function b(){var a=0<arguments.length&&
void 0!==arguments[0]?arguments[0]:document.location.href,e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:document.title;g(this,b);var d=p(this,l(b).call(this));d.url=encodeURIComponent(a);d.title=encodeURIComponent(e);d.createEvents=d.createEvents.bind(m(d));return d}n(b,c);k(b,[{key:"getPreparedData",value:function(a){var b=a.dataset.url?encodeURIComponent(a.dataset.url):this.url;a=a.dataset.title?encodeURIComponent(a.dataset.title):this.title;b="https://facebook.com/sharer/sharer.php?u=".concat(b,
"&t=").concat(a);return{callback:this.callback,share_url:b,windowTitle:"Share this",windowWidth:640,windowHeight:480}}},{key:"shareWindow",value:function(){var a=document.querySelectorAll('[data-social="facebook"]');return this.createEvents(a)}},{key:"getCounter",value:function(){var a=document.createElement("script"),b=("goodshare_"+Math.random()).replace(".",""),d=document.querySelectorAll('[data-counter="facebook"]'),c="https://graph.facebook.com/?id=".concat(this.url,"&callback=").concat(b);0<
d.length&&(window[b]=function(b){q(d).forEach(function(a){a.innerHTML=b.share?b.share.share_count:0});null!==a.parentNode&&a.parentNode.removeChild(a)},a.src=c,document.body.appendChild(a))}}]);return b}(h),y=function(c){function b(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:document.location.href,e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:document.title,d=2<arguments.length&&void 0!==arguments[2]?arguments[2]:document.querySelector('meta[name="description"]');g(this,
b);var c=p(this,l(b).call(this));c.url=encodeURIComponent(a);c.title=encodeURIComponent(e);c.description=d?encodeURIComponent(d.content):"";c.createEvents=c.createEvents.bind(m(c));return c}n(b,c);k(b,[{key:"getPreparedData",value:function(a){var b=a.dataset.url?encodeURIComponent(a.dataset.url):this.url,d=a.dataset.title?encodeURIComponent(a.dataset.title):this.title;a=a.dataset.description?encodeURIComponent(a.dataset.description):this.description;b="https://www.linkedin.com/shareArticle?url=".concat(b,
"&text=").concat(d,"&summary=").concat(a,"&mini=true");return{callback:this.callback,share_url:b,windowTitle:"Share this",windowWidth:640,windowHeight:480}}},{key:"shareWindow",value:function(){var a=document.querySelectorAll('[data-social="linkedin"]');return this.createEvents(a)}},{key:"getCounter",value:function(){var a=document.createElement("script"),b=("goodshare_"+Math.random()).replace(".",""),d=document.querySelectorAll('[data-counter="linkedin"]'),c="https://www.linkedin.com/countserv/count/share?url=".concat(this.url,
"&callback=").concat(b);0<d.length&&(window[b]=function(b){q(d).forEach(function(a){a.innerHTML=b.count});a.parentNode.removeChild(a)},a.src=c,document.body.appendChild(a))}}]);return b}(h),z=function(c){function b(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:document.location.href,e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:document.title,d=2<arguments.length&&void 0!==arguments[2]?arguments[2]:document.querySelector('meta[name="description"]');g(this,b);var c=p(this,
l(b).call(this));c.url=encodeURIComponent(a);c.title=encodeURIComponent(e);c.description=d?encodeURIComponent(d.content):"";c.createEvents=c.createEvents.bind(m(c));return c}n(b,c);k(b,[{key:"getPreparedData",value:function(a){var b=a.dataset.url?encodeURIComponent(a.dataset.url):this.url,c=a.dataset.title?encodeURIComponent(a.dataset.title):this.title;a=a.dataset.description?encodeURIComponent(a.dataset.description):this.description;b="https://www.tumblr.com/widgets/share/tool?canonicalUrl=".concat(b,
"&title=").concat(c,"&caption=").concat(a,"&posttype=link");return{callback:this.callback,share_url:b,windowTitle:"Share this",windowWidth:640,windowHeight:480}}},{key:"shareWindow",value:function(){var a=document.querySelectorAll('[data-social="tumblr"]');return this.createEvents(a)}},{key:"getCounter",value:function(){var a=document.createElement("script"),b=("goodshare_"+Math.random()).replace(".",""),c=document.querySelectorAll('[data-counter="tumblr"]'),f="https://api.tumblr.com/v2/share/stats?url=".concat(this.url,
"&callback=").concat(b);0<c.length&&(window[b]=function(b){q(c).forEach(function(a){a.innerHTML=b.response.note_count});null!==a.parentNode&&a.parentNode.removeChild(a)},a.src=f,document.body.appendChild(a))}}]);return b}(h),A=function(c){function b(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:document.location.href,e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:document.querySelector('meta[name="description"]'),c=2<arguments.length&&void 0!==arguments[2]?arguments[2]:
document.querySelector('link[rel="apple-touch-icon"]');g(this,b);var f=p(this,l(b).call(this));f.url=encodeURIComponent(a);f.description=e?encodeURIComponent(e.content):"";f.image=c?encodeURIComponent(c.href):"";f.createEvents=f.createEvents.bind(m(f));return f}n(b,c);k(b,[{key:"getPreparedData",value:function(a){var b=a.dataset.url?encodeURIComponent(a.dataset.url):this.url,c=a.dataset.description?encodeURIComponent(a.dataset.description):this.description;a=a.dataset.image?encodeURIComponent(a.dataset.image):
this.image;b="https://www.pinterest.com/pin/create/button/?url=".concat(b,"&description=").concat(c,"&media=").concat(a);return{callback:this.callback,share_url:b,windowTitle:"Share this",windowWidth:640,windowHeight:480}}},{key:"shareWindow",value:function(){var a=document.querySelectorAll('[data-social="pinterest"]');return this.createEvents(a)}},{key:"getCounter",value:function(){var a=document.createElement("script"),b=("goodshare_"+Math.random()).replace(".",""),c=document.querySelectorAll('[data-counter="pinterest"]'),
f="https://api.pinterest.com/v1/urls/count.json?url=".concat(this.url,"&callback=").concat(b);0<c.length&&(window[b]=function(b){q(c).forEach(function(a){a.innerHTML=0<b.length?b.count:0});null!==a.parentNode&&a.parentNode.removeChild(a)},a.src=f,document.body.appendChild(a))}}]);return b}(h),B=function(c){function b(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:document.location.href,c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:document.title;g(this,b);var d=p(this,l(b).call(this));
d.url=encodeURIComponent(a);d.title=encodeURIComponent(c);d.createEvents=d.createEvents.bind(m(d));return d}n(b,c);k(b,[{key:"getPreparedData",value:function(a){var b=a.dataset.url?encodeURIComponent(a.dataset.url):this.url;a=a.dataset.title?encodeURIComponent(a.dataset.title):this.title;b="https://reddit.com/submit?url=".concat(b,"&title=").concat(a);return{callback:this.callback,share_url:b,windowTitle:"Share this",windowWidth:640,windowHeight:480}}},{key:"shareWindow",value:function(){var a=document.querySelectorAll('[data-social="reddit"]');
return this.createEvents(a)}},{key:"getCounter",value:function(){var a=document.createElement("script"),b=("goodshare_"+Math.random()).replace(".",""),c=document.querySelectorAll('[data-counter="reddit"]'),f="https://www.reddit.com/api/info.json?url=".concat(this.url,"&callback=").concat(b);0<c.length&&(window[b]=function(b){q(c).forEach(function(a){if(0<b.data.children.length){for(var c=0,e=0;e<b.data.children.length;e++)c+=b.data.children[e].data.score;a.innerHTML=c}else a.innerHTML=0});a.parentNode.removeChild(a)},
a.src=f,document.body.appendChild(a))}}]);return b}(h),C=function(c){function b(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:document.location.href,c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:document.title;g(this,b);var d=p(this,l(b).call(this));d.url=encodeURIComponent(a);d.title=encodeURIComponent(c);d.createEvents=d.createEvents.bind(m(d));return d}n(b,c);k(b,[{key:"getPreparedData",value:function(a){var b=a.dataset.url?encodeURIComponent(a.dataset.url):this.url;
a=a.dataset.title?encodeURIComponent(a.dataset.title):this.title;b="https://getpocket.com/save?url=".concat(b,"&title=").concat(a);return{callback:this.callback,share_url:b,windowTitle:"Share this",windowWidth:640,windowHeight:480}}},{key:"shareWindow",value:function(){var a=document.querySelectorAll('[data-social="pocket"]');return this.createEvents(a)}},{key:"getCounter",value:function(){var a=document.createElement("script"),b=("goodshare_"+Math.random()).replace(".",""),c=document.querySelectorAll('[data-counter="pocket"]'),
f="https://query.yahooapis.com/v1/public/yql?q="+encodeURIComponent('select * from html where url="https://widgets.getpocket.com/v1/button?label=pocket&count=vertical&v=1&url='+this.url+"&src="+this.url+'" and xpath="*"')+"&callback="+b;0<c.length&&(window[b]=function(b){q(c).forEach(function(a){a.innerHTML=0<b.results.length?b.results[0].match(/em id="cnt">(\d+)</)[1]/1:0});a.parentNode.removeChild(a)},a.src=f,document.body.appendChild(a))}}]);return b}(h),D=function(c){function b(){var a=0<arguments.length&&
void 0!==arguments[0]?arguments[0]:document.location.href,c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:document.title;g(this,b);var d=p(this,l(b).call(this));d.url=encodeURIComponent(a);d.title=encodeURIComponent(c);d.createEvents=d.createEvents.bind(m(d));return d}n(b,c);k(b,[{key:"getPreparedData",value:function(a){var b=a.dataset.url?encodeURIComponent(a.dataset.url):this.url;a=a.dataset.title?encodeURIComponent(a.dataset.title):this.title;b="https://twitter.com/share?url=".concat(b,
"&text=").concat(a);return{callback:this.callback,share_url:b,windowTitle:"Share this",windowWidth:640,windowHeight:480}}},{key:"shareWindow",value:function(){var a=document.querySelectorAll('[data-social="twitter"]');return this.createEvents(a)}}]);return b}(h),E=function(c){function b(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:document.location.href,c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:document.title,d=2<arguments.length&&void 0!==arguments[2]?arguments[2]:
document.querySelector('meta[name="description"]');g(this,b);var f=p(this,l(b).call(this));f.url=encodeURIComponent(a);f.title=encodeURIComponent(c);f.description=d?encodeURIComponent(d.content):"";f.createEvents=f.createEvents.bind(m(f));return f}n(b,c);k(b,[{key:"getPreparedData",value:function(a){var b=a.dataset.url?encodeURIComponent(a.dataset.url):this.url,c=a.dataset.title?encodeURIComponent(a.dataset.title):this.title;a=a.dataset.description?encodeURIComponent(a.dataset.description):this.description;
b="https://www.evernote.com/clip.action?url=".concat(b,"&title=").concat(c,"&body=").concat(a);return{callback:this.callback,share_url:b,windowTitle:"Share this",windowWidth:640,windowHeight:480}}},{key:"shareWindow",value:function(){var a=document.querySelectorAll('[data-social="evernote"]');return this.createEvents(a)}}]);return b}(h),F=function(c){function b(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:document.location.href,c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:
document.title;g(this,b);var d=p(this,l(b).call(this));d.url=encodeURIComponent(a);d.title=encodeURIComponent(c);d.createEvents=d.createEvents.bind(m(d));return d}n(b,c);k(b,[{key:"getPreparedData",value:function(a){var b=a.dataset.url?encodeURIComponent(a.dataset.url):this.url;a=a.dataset.title?encodeURIComponent(a.dataset.title):this.title;b="https://www.instapaper.com/edit?url=".concat(b,"&title=").concat(a);return{callback:this.callback,share_url:b,windowTitle:"Share this",windowWidth:640,windowHeight:480}}},
{key:"shareWindow",value:function(){var a=document.querySelectorAll('[data-social="instapaper"]');return this.createEvents(a)}}]);return b}(h),G=function(c){function b(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:document.location.href;g(this,b);var c=p(this,l(b).call(this));c.url=encodeURIComponent(a);c.createEvents=c.createEvents.bind(m(c));return c}n(b,c);k(b,[{key:"getPreparedData",value:function(a){a=a.dataset.url?encodeURIComponent(a.dataset.url):this.url;a="sms:?&body=".concat(a);
return{callback:this.callback,share_url:a,windowTitle:"Share this",windowWidth:640,windowHeight:480}}},{key:"shareWindow",value:function(){var a=document.querySelectorAll('[data-social="sms"]');return this.createEvents(a)}}]);return b}(h),H=function(c){function b(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:document.location.href;g(this,b);var c=p(this,l(b).call(this));c.url=encodeURIComponent(a);c.createEvents=c.createEvents.bind(m(c));return c}n(b,c);k(b,[{key:"getPreparedData",
value:function(a){a=a.dataset.url?encodeURIComponent(a.dataset.url):this.url;a="https://web.skype.com/share?".concat(a);return{callback:this.callback,share_url:a,windowTitle:"Share this",windowWidth:640,windowHeight:480}}},{key:"shareWindow",value:function(){var a=document.querySelectorAll('[data-social="skype"]');return this.createEvents(a)}}]);return b}(h),I=function(c){function b(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:document.location.href;g(this,b);var c=p(this,l(b).call(this));
c.url=encodeURIComponent(a);c.createEvents=c.createEvents.bind(m(c));return c}n(b,c);k(b,[{key:"getPreparedData",value:function(a){var b=a.dataset.url?encodeURIComponent(a.dataset.url):this.url;a=a.dataset.rhash?a.dataset.rhash:null;var c="https://t.me/share/url?url=".concat(b);null!==a&&(c="https://t.me/iv?url=".concat(b,"&rhash=").concat(a));return{callback:this.callback,share_url:c,windowTitle:"Share this",windowWidth:640,windowHeight:480}}},{key:"shareWindow",value:function(){var a=document.querySelectorAll('[data-social="telegram"]');
return this.createEvents(a)}}]);return b}(h),J=function(c){function b(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:document.location.href;g(this,b);var c=p(this,l(b).call(this));c.url=encodeURIComponent(a);c.createEvents=c.createEvents.bind(m(c));return c}n(b,c);k(b,[{key:"getPreparedData",value:function(a){a=a.dataset.url?encodeURIComponent(a.dataset.url):this.url;a="https://wa.me/?text=".concat(a);return{callback:this.callback,share_url:a,windowTitle:"Share this",windowWidth:640,
windowHeight:480}}},{key:"shareWindow",value:function(){var a=document.querySelectorAll('[data-social="whatsapp"]');return this.createEvents(a)}}]);return b}(h);h=function(c){function b(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:document.location.href,c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:document.title;g(this,b);var d=p(this,l(b).call(this));d.url=encodeURIComponent(a);d.title=encodeURIComponent(c);d.createEvents=d.createEvents.bind(m(d));return d}n(b,c);k(b,
[{key:"getPreparedData",value:function(a){var b=a.dataset.url?encodeURIComponent(a.dataset.url):this.url;a=a.dataset.title?encodeURIComponent(a.dataset.title):this.title;b="mailto:?subject=".concat(a,"&body=").concat(b);return{callback:this.callback,share_url:b,useLocation:!0}}},{key:"shareWindow",value:function(){var a=document.querySelectorAll('[data-social="email"]');return this.createEvents(a)}}]);return b}(h);var K=[u,y,z,A,B,C,D,E,F,G,H,I,J,h];u=function(){function c(){g(this,c);this.providers=
K;this.getProviders()}k(c,[{key:"setShareCallback",value:function(b){this.providers=this.providers.map(function(a){return a.setShareCallback(b)})}},{key:"getProviders",value:function(){return this.providers=this.providers.map(function(b){return(new b).getInstance()})}},{key:"reNewAllInstance",value:function(){this.providers=this.providers.map(function(b){return b.reNewInstance()})}}]);return c}();window._goodshare=new u})();