forked from djds4rce/angular-socialshare
-
Notifications
You must be signed in to change notification settings - Fork 0
/
angular-socialshare.min.js
1 lines (1 loc) · 3 KB
/
angular-socialshare.min.js
1
"use strict";angular.module("djds4rce.angular-socialshare",[]).factory("$FB",["$window",function(e){return{init:function(t){if(t){this.fbId=t;e.fbAsyncInit=function(){FB.init({appId:t,channelUrl:"app/channel.html",status:true,xfbml:true})};(function(e){var t,n="facebook-jssdk",r=e.getElementsByTagName("script")[0];if(e.getElementById(n)){return}t=e.createElement("script");t.id=n;t.async=true;t.src="//connect.facebook.net/en_US/all.js";r.parentNode.insertBefore(t,r)})(document)}else{throw"FB App Id Cannot be blank"}}}}]).directive("facebook",["$timeout","$http",function(e,t){return{scope:{shares:"="},transclude:true,template:'<div class="facebookButton"><div class="pluginButton"><div class="pluginButtonContainer"><div class="pluginButtonImage"><button type="button"><i class="pluginButtonIcon img sp_plugin-button-2x sx_plugin-button-2x_favblue"></i></button></div><span class="pluginButtonLabel">Share</span></div></div></div><div class="facebookCount"><div class="pluginCountButton pluginCountNum"><span ng-transclude></span>'+'</div><div class="pluginCountButtonNub"><s></s><i></i></div></div>',link:function(n,r,i){if(i.shares){t.get("https://api.facebook.com/method/links.getStats?urls="+i.url+"&format=json").success(function(e){var t=e[0].share_count.toString();var r="";if(t.length>6){if(t.slice(-6,-5)!="0"){r="."+t.slice(-6,-5)}t=t.slice(0,-6);t=t+r+"M"}else if(t.length>3){if(t.slice(-3,-2)!="0"){r="."+t.slice(-3,-2)}t=t.slice(0,-3);t=t+r+"k"}n.shares=t}).error(function(){n.shares=0})}e(function(){r.bind("click",function(e){FB.ui({method:"share",href:i.url});e.preventDefault()})})}}}]).directive("twitter",["$timeout",function(e){return{link:function(t,n,r){e(function(){twttr.widgets.createShareButton(r.url,n[0],function(){},{count:r.count,text:r.text,via:r.via,size:r.size})})}}}]).directive("linkdin",["$timeout","$http","$window",function(e,t,n){return{scope:{shares:"="},transclude:true,template:'<div class="linkedinButton"><div class="pluginButton"><div class="pluginButtonContainer"><div class="pluginButtonImage">in</div><span class="pluginButtonLabel"><span>Share</span></span></div></div></div><div class="linkedinCount"><div class="pluginCountButton"><div class="pluginCountButtonRight"><div class="pluginCountButtonLeft"><span ng-transclude></span></div></div></div></div>',link:function(r,i,s){if(s.shares){t.jsonp("http://www.linkedin.com/countserv/count/share?url="+s.link+"&callback=JSON_CALLBACK&format=jsonp").success(function(e){r.shares=e.count.toLocaleString()}).error(function(){r.shares=0})}e(function(){i.bind("click",function(){var e=encodeURIComponent(s.url).replace(/'/g,"%27").replace(/"/g,"%22");n.open("//www.linkedin.com/shareArticle?mini=true&url="+e+"&title="+s.title+"&summary="+s.summary)})})}}}]).directive("gplus",[function(){return{link:function(e,t,n){if(typeof gapi=="undefined"){(function(){var e=document.createElement("script");e.type="text/javascript";e.async=true;e.src="https://apis.google.com/js/plusone.js";var t=document.getElementsByTagName("script")[0];t.parentNode.insertBefore(e,t)})()}}}}])