feat(sharing): Load widgets from service

This commit is contained in:
Sabe Jones
2015-10-22 14:37:29 -04:00
parent 281411f423
commit e2cfd1bd54
5 changed files with 43 additions and 20 deletions

View File

@@ -1,8 +1,10 @@
"use strict"; "use strict";
angular.module('habitrpg').controller("FooterCtrl", angular.module('habitrpg').controller("FooterCtrl",
['$scope', '$rootScope', 'User', '$http', 'Notification', 'ApiUrl', ['$scope', '$rootScope', 'User', '$http', 'Notification', 'ApiUrl', 'Social',
function($scope, $rootScope, User, $http, Notification, ApiUrl) { function($scope, $rootScope, User, $http, Notification, ApiUrl, Social) {
$scope.loadWidgets = Social.loadWidgets;
if(env.isStaticPage){ if(env.isStaticPage){
$scope.languages = env.avalaibleLanguages; $scope.languages = env.avalaibleLanguages;
@@ -31,20 +33,8 @@ function($scope, $rootScope, User, $http, Notification, ApiUrl) {
// Stripe // Stripe
$.getScript('//checkout.stripe.com/v2/checkout.js'); $.getScript('//checkout.stripe.com/v2/checkout.js');
// Twitter // Social sharing buttons
$.getScript('https://platform.twitter.com/widgets.js'); loadWidgets();
// Facebook
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.5";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
// Tumblr
$.getScript('https://assets.tumblr.com/share-button.js');
/* Google Content Experiments /* Google Content Experiments
if (window.env.NODE_ENV === 'production') { if (window.env.NODE_ENV === 'production') {

View File

@@ -1,11 +1,12 @@
"use strict"; "use strict";
habitrpg.controller("UserCtrl", ['$rootScope', '$scope', '$location', 'User', '$http', '$state', 'Guide', 'Shared', 'Content', 'Stats', habitrpg.controller("UserCtrl", ['$rootScope', '$scope', '$location', 'User', '$http', '$state', 'Guide', 'Shared', 'Content', 'Stats', 'Social',
function($rootScope, $scope, $location, User, $http, $state, Guide, Shared, Content, Stats) { function($rootScope, $scope, $location, User, $http, $state, Guide, Shared, Content, Stats, Social) {
$scope.profile = User.user; $scope.profile = User.user;
$scope.statCalc = Stats; $scope.statCalc = Stats;
$.getScript('https://platform.twitter.com/widgets.js'); $scope.loadWidgets = Social.loadWidgets;
$scope.hideUserAvatar = function() { $scope.hideUserAvatar = function() {
$(".userAvatar").hide(); $(".userAvatar").hide();

View File

@@ -0,0 +1,29 @@
'use strict';
(function(){
angular
.module('habitrpg')
.factory('Social', socialFactory);
socialFactory.$inject = [];
function socialFactory() {
function loadWidgets() {
// Facebook
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.5";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
// Tumblr
$.getScript('https://assets.tumblr.com/share-button.js');
// Twitter
$.getScript('https://platform.twitter.com/widgets.js');
}
}
}());

View File

@@ -52,6 +52,7 @@
"js/services/challengeServices.js", "js/services/challengeServices.js",
"js/services/paymentServices.js", "js/services/paymentServices.js",
"js/services/questServices.js", "js/services/questServices.js",
"js/services/socialServices.js",
"js/services/statServices.js", "js/services/statServices.js",
"js/filters/money.js", "js/filters/money.js",

View File

@@ -16,5 +16,7 @@ script(type='text/ng-template', id='modals/levelUp.html')
p=env.t('fullyHealed') p=env.t('fullyHealed')
br br
button.btn.btn-primary(ng-click='$close()')=env.t('huzzah') button.btn.btn-primary(ng-click='$close()')=env.t('huzzah')
.modal-footer(style='margin-top:0') .modal-footer(style='margin-top:0', ng-init='loadWidgets()')
a.twitter-share-button(href='https://twitter.com/intent/tweet?text=I+got+to+Level+{{::user.stats.lvl}}+in+Habitica+by+improving+my+real-life+habits!&via=habitica&url=https://habitrpg-gamma.herokuapp.com/social/level-up&count=none')=env.t('tweet') a.twitter-share-button(href='https://twitter.com/intent/tweet?text=I+got+to+Level+{{::user.stats.lvl}}+in+Habitica+by+improving+my+real-life+habits!&via=habitica&url=https://habitrpg-gamma.herokuapp.com/social/level-up&count=none')=env.t('tweet')
.fb-share-button(data-href='https://habitrpg-gamma.herokuapp.com/social/level-up', data-layout='button')
a.tumblr-share-button(data-href='https://habitrpg-gamma.herokuapp.com/social/level-up', data-notes='none')