|
var MULTI = 1000; |
|
var DEC = 100; |
|
|
|
module.exports =function (loco, win, $http){ |
|
var share = { |
|
'fb' : { |
|
icon : 'facebook-square', |
|
share: function () { |
|
return 'http://www.facebook.com/sharer.php?u=' + loco.absUrl(); |
|
}, |
|
count : function () { |
|
return "https://graph.facebook.com/?callback=JSON_CALLBACK&id="+ loco.absUrl(); |
|
}, |
|
get: function(data) { |
|
return data.shares; |
|
} |
|
}, |
|
twitter : { |
|
icon : 'twitter-square', |
|
share: function (text, via) { |
|
return 'http://twitter.com/share?text=' + text + '&url=' + loco.absUrl() + '&via=' + via; |
|
}, |
|
count : function () { |
|
return "https://cdn.api.twitter.com/1/urls/count.json?callback=JSON_CALLBACK&url="+ loco.absUrl(); |
|
}, |
|
get: function(data) { |
|
return data.count; |
|
} |
|
}, |
|
google : { |
|
icon : 'google-plus-square', |
|
share: function () { |
|
return 'https://plus.google.com/share?url='+ loco.absUrl(); |
|
} |
|
}, |
|
tumblr : { |
|
icon : 'tumblr-square', |
|
share: function () { |
|
return 'https://www.tumblr.com/widgets/share/tool?shareSource=legacy&canonicalUrl=&url=' + loco.absUrl(); |
|
} |
|
}, |
|
reddit : { |
|
icon : 'reddit-square', |
|
share: function () { |
|
return 'https://www.reddit.com/submit?url=' + loco.absUrl(); |
|
} |
|
}, |
|
linkedin : { |
|
icon : 'linkedin-square', |
|
share: function () { |
|
return 'https://www.linkedin.com/shareArticle?mini=true&url=' + loco.absUrl(); |
|
}, |
|
count : function () { |
|
return "https://www.linkedin.com/countserv/count/share?callback=JSON_CALLBACK&format=jsonp&url="+ loco.absUrl(); |
|
}, |
|
get: function(data) { |
|
return data.count; |
|
} |
|
}, |
|
pinterest : { |
|
icon : 'pinterest-square', |
|
share: function (text, media) { |
|
return 'http://pinterest.com/pin/create/button/?url=' + loco.absUrl() + '&description=' + text + '&media=' + media ; |
|
}, |
|
count : function () { |
|
return "https://api.pinterest.com/v1/urls/count.json?callback=JSON_CALLBACK&url="+ loco.absUrl(); |
|
}, |
|
get : function (data) { |
|
return data.count; |
|
} |
|
}, |
|
|
|
xing : { |
|
icon : 'xing-square', |
|
share: function () { |
|
return 'https://www.xing-share.com/app/user?op=share;sc_p=xing-share;url=' + loco.absUrl(); |
|
} |
|
}, |
|
email : { |
|
icon : 'envelope-o', |
|
share: function (text) { |
|
return 'mailto:?subject=' + text + '&body=' + loco.absUrl(); |
|
} |
|
}, |
|
|
|
adn : { |
|
icon : 'adn', |
|
share: function () { |
|
return 'idont'; |
|
} |
|
} |
|
}; |
|
|
|
return { |
|
restrict: 'A', |
|
scope: { |
|
share : '@' |
|
}, |
|
bindToController: true, |
|
link : function (scope, ele, attr) { |
|
scope.count = ''; |
|
scope.more = ''; |
|
scope.tos = share[ scope.share ]; |
|
if(scope.tos.count){ |
|
$http.jsonp(scope.tos.count()).success(function (data) { |
|
scope.count = scope.tos.get(data); |
|
if( scope.count >= MULTI ){ |
|
scope.count = Math.round( (scope.count / MULTI) * DEC) / DEC; |
|
scope.more = 'k'; |
|
if( scope.count >= MULTI ){ |
|
scope.count = Math.round( (scope.count / MULTI) * DEC) / DEC; |
|
scope.more = 'M'; |
|
} |
|
} |
|
}); |
|
} |
|
|
|
ele.on('click', function (e) { |
|
var left = (screen.width/2)- 300; |
|
var top = (screen.height/2)- 200; |
|
var newwindow = win.open(scope.tos.share( attr.text, attr.via ),'Share Galeph','location=1,status=1,scrollbars=1,height=400,width=600,top='+top+',left='+left); |
|
if (win.focus) newwindow.focus(); |
|
}); |
|
}, |
|
template : '<i class="fa fa-{{tos.icon}} fa-lg">{{count + more}}</i>', |
|
}; |
|
}; |
|
|
|
module.exports.$inject = [ '$location', '$window', '$http' ]; |