|
function humanifyCount(number) { |
|
var count = number.toString(); |
|
var decimal = ''; |
|
if (count.length > 6) { |
|
if (count.slice(-6,-5) !== '0') { |
|
decimal = '.'+count.slice(-6,-5); |
|
} |
|
count = count.slice(0, -6); |
|
count = count + decimal + 'M'; |
|
} else if (count.length > 3) { |
|
if (count.slice(-3,-2) !== '0') { |
|
decimal = '.' + count.slice(-3, -2); |
|
} |
|
count = count.slice(0, -3); |
|
count = count + decimal + 'k'; |
|
} |
|
return count; |
|
} |
|
|
|
getRingerApp.filter('humanCount', function() { |
|
return function (number) { |
|
return typeof number === 'number' ? humanifyCount(number) : ''; |
|
}; |
|
}); |
|
|
|
getRingerApp.directive('share', function ($compile, $http) { |
|
return { |
|
restrict: 'AE', |
|
link: function (scope, element, attrs) { |
|
var url, popup; |
|
|
|
$http.get('https://api.facebook.com/method/links.getStats?urls=' + encodeURIComponent(attrs.url) + '&format=json').success(function (data) { |
|
scope.share_count = data[0].share_count; |
|
scope.like_count = data[0].like_count; |
|
scope.click_count = data[0].click_count; |
|
scope.total_count = data[0].total_count; |
|
}); |
|
|
|
element.on('click', function () { |
|
if (attrs.share === 'facebook') { |
|
url = 'https://www.facebook.com/sharer/sharer.php?u=' + encodeURIComponent(attrs.url) + '&display=popup'; |
|
popup = window.open(url, 'share', 'toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,height=300,width=611,top=' + ((screen.height / 2) - (300 / 2)) + ',left=' + ((screen.width / 2) - (611 / 2))); |
|
if (window.focus) { |
|
popup.focus(); |
|
} |
|
} |
|
}); |
|
} |
|
}; |
|
}); |