2013-08-28 16:53:55 +00:00
"use strict" ;
2015-01-18 01:43:37 +00:00
angular . module ( 'habitrpg' ) . controller ( "FooterCtrl" ,
2015-10-22 18:37:29 +00:00
[ '$scope' , '$rootScope' , 'User' , '$http' , 'Notification' , 'ApiUrl' , 'Social' ,
function ( $scope , $rootScope , User , $http , Notification , ApiUrl , Social ) {
$scope . loadWidgets = Social . loadWidgets ;
2013-08-28 16:53:55 +00:00
2015-01-27 14:48:57 +00:00
if ( env . isStaticPage ) {
2016-02-19 17:42:03 +00:00
$scope . languages = env . availableLanguages ;
$scope . selectedLanguage = _ . find ( env . availableLanguages , { code : env . language . code } ) ;
2014-08-03 16:23:13 +00:00
2015-01-18 01:43:37 +00:00
$rootScope . selectedLanguage = $scope . selectedLanguage ;
$scope . changeLang = function ( ) {
window . location = '?lang=' + $scope . selectedLanguage . code ;
2014-08-03 16:23:13 +00:00
}
2015-01-18 01:43:37 +00:00
}
2014-08-03 16:23:13 +00:00
2015-01-18 01:43:37 +00:00
/ * *
External Scripts
JS files not needed right away ( google charts ) or entirely optional ( analytics )
Each file gets loaded async via $ . getScript , so it doesn ' t bog page - load
* /
2015-06-08 16:55:15 +00:00
2015-01-18 01:43:37 +00:00
$scope . deferredScripts = function ( ) {
2013-08-28 16:53:55 +00:00
2015-06-03 20:05:55 +00:00
// Amazon Payments
2015-06-25 17:05:05 +00:00
var amazonPaymentsUrl = 'https://static-na.payments-amazon.com/OffAmazonPayments/us/' +
2015-06-26 16:14:27 +00:00
( window . env . NODE _ENV === 'production' ? '' : 'sandbox/' ) + 'js/Widgets.js' ;
2015-06-25 17:05:05 +00:00
$ . getScript ( amazonPaymentsUrl ) ;
2015-06-03 20:05:55 +00:00
2015-01-18 01:43:37 +00:00
// Stripe
$ . getScript ( '//checkout.stripe.com/v2/checkout.js' ) ;
2013-08-28 16:53:55 +00:00
2015-07-16 16:22:19 +00:00
/ * G o o g l e C o n t e n t E x p e r i m e n t s
2015-03-20 23:02:45 +00:00
if ( window . env . NODE _ENV === 'production' ) {
2015-07-02 21:13:22 +00:00
$ . getScript ( '//www.google-analytics.com/cx/api.js?experiment=boVO4eEyRfysNE5D53nCMQ' , function ( ) {
2015-03-30 22:43:26 +00:00
$rootScope . variant = cxApi . chooseVariation ( ) ;
2015-03-20 20:44:18 +00:00
$rootScope . $apply ( ) ;
} )
2015-07-16 16:22:19 +00:00
} * /
2013-08-28 16:53:55 +00:00
2015-01-18 01:43:37 +00:00
// Scripts only for desktop
if ( ! window . env . IS _MOBILE ) {
// Add This
//$.getScript("//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-5016f6cc44ad68a4"); //FIXME why isn't this working when here? instead it's now in <head>
var addthisServices = 'facebook,twitter,googleplus,tumblr,' + window . env . BASE _URL . replace ( 'https://' , '' ) . replace ( 'http://' , '' ) ;
window . addthis _config = {
ui _click : true ,
services _custom : {
name : "Download" ,
url : window . env . BASE _URL + "/export/avatar-" + User . user . _id + ".png" ,
icon : window . env . BASE _URL + "/favicon.ico"
} ,
services _expanded : addthisServices ,
services _compact : addthisServices
} ;
2013-08-28 16:53:55 +00:00
2015-01-18 01:43:37 +00:00
// Google Charts
$ . getScript ( "//www.google.com/jsapi" , function ( ) {
google . load ( "visualization" , "1" , {
packages : [ "corechart" ] ,
callback : function ( ) { }
2013-08-28 16:53:55 +00:00
} ) ;
2015-01-18 01:43:37 +00:00
} ) ;
2013-10-31 22:14:19 +00:00
}
2015-01-18 01:43:37 +00:00
}
2013-08-28 16:53:55 +00:00
2015-01-18 01:43:37 +00:00
/ * *
* Debug functions . Note that the server route for gems is only available if process . env . DEBUG = true
* /
2016-04-18 20:42:59 +00:00
if ( _ . contains ( [ 'development' , 'test' ] , window . env . NODE _ENV ) ) {
2015-09-13 07:19:34 +00:00
2015-01-18 01:43:37 +00:00
$scope . setHealthLow = function ( ) {
User . set ( {
'stats.hp' : 1
} ) ;
2015-09-13 07:19:34 +00:00
} ;
2016-05-05 18:02:56 +00:00
//@TODO: Route?
2015-03-07 08:39:43 +00:00
$scope . addMissedDay = function ( numberOfDays ) {
if ( ! confirm ( "Are you sure you want to reset the day by " + numberOfDays + " day(s)?" ) ) return ;
var dayBefore = moment ( User . user . lastCron ) . subtract ( numberOfDays , 'days' ) . toDate ( ) ;
2015-01-18 01:43:37 +00:00
User . set ( { 'lastCron' : dayBefore } ) ;
2015-03-07 08:39:43 +00:00
Notification . text ( '-' + numberOfDays + ' day(s), remember to refresh' ) ;
2015-09-13 07:19:34 +00:00
} ;
2015-01-18 01:43:37 +00:00
$scope . addTenGems = function ( ) {
2016-05-05 18:02:56 +00:00
User . addTenGems ( ) ;
2015-09-13 07:19:34 +00:00
} ;
2015-09-02 17:12:48 +00:00
$scope . addHourglass = function ( ) {
2016-05-05 18:02:56 +00:00
User . addHourglass ( ) ;
2015-09-13 07:19:34 +00:00
} ;
2015-09-02 17:12:48 +00:00
$scope . addGold = function ( ) {
2015-09-13 03:34:58 +00:00
User . set ( {
2015-01-18 01:43:37 +00:00
'stats.gp' : User . user . stats . gp + 500 ,
} ) ;
2015-09-13 07:19:34 +00:00
} ;
2015-03-13 03:52:54 +00:00
$scope . addMana = function ( ) {
User . set ( {
'stats.mp' : User . user . stats . mp + 500 ,
} ) ;
2015-09-13 07:19:34 +00:00
} ;
2015-01-18 01:43:37 +00:00
$scope . addLevelsAndGold = function ( ) {
User . set ( {
'stats.exp' : User . user . stats . exp + 10000 ,
'stats.gp' : User . user . stats . gp + 10000 ,
'stats.mp' : User . user . stats . mp + 10000
} ) ;
2015-09-13 07:19:34 +00:00
} ;
2015-01-18 01:43:37 +00:00
$scope . addOneLevel = function ( ) {
User . set ( {
'stats.exp' : User . user . stats . exp + ( Math . round ( ( ( Math . pow ( User . user . stats . lvl , 2 ) * 0.25 ) + ( 10 * User . user . stats . lvl ) + 139.75 ) / 10 ) * 10 )
} ) ;
2015-09-13 07:19:34 +00:00
} ;
2015-01-18 01:43:37 +00:00
$scope . addBossQuestProgressUp = function ( ) {
2016-05-05 18:02:56 +00:00
//@TODO: Route?
2015-01-18 01:43:37 +00:00
User . set ( {
'party.quest.progress.up' : User . user . party . quest . progress . up + 1000
} ) ;
2015-09-13 07:19:34 +00:00
} ;
2015-01-18 01:43:37 +00:00
}
} ] )