angular.module('app', [ 'app.config', 'app.auth', 'app.app', 'app.templates', 'ImgCache', 'LocalStorageModule', 'ngCordova.plugins.nativeStorage', //'ngCordova.plugins.googleAnalytics', 'ngCordova.plugins.statusbar', 'ion-gallery' ]) .config(function ($ionicConfigProvider, localStorageServiceProvider) { $ionicConfigProvider.navBar.alignTitle('center'); $ionicConfigProvider.backButton.text('').icon('ion-chevron-left'); $ionicConfigProvider.views.swipeBackEnabled(false); $ionicConfigProvider.tabs.position('top'); //localStorageServiceProvider.setPrefix('cadoro'); }) .config(function($compileProvider){ $compileProvider.debugInfoEnabled(false); $compileProvider.imgSrcSanitizationWhitelist(/^\s*.*:/); }) .config(function($stateProvider, $urlRouterProvider) { $stateProvider .state('welcome', { cache: false, url: '/welcome', templateUrl: 'templates/auth-welcome.html', controller: 'AuthWelcomeController' }) .state('welcome_registrazione', { cache: false, url: '/welcome/registrazione', templateUrl: 'templates/auth-welcome-registrazione.html', controller: 'AuthWelcomeRegistrazioneController' }) .state('app', { cache: true, url: '/app', abstract: true, templateUrl: 'templates/app.html', controller: 'AppController' }) .state('app.home', { cache: true, url: '/home', views: { 'content': { templateUrl: 'templates/app-home.html', controller: 'AppHomeController' } } }) .state('app.lista_spesa', { cache: true, url: '/lista-spesa', views: { 'content': { templateUrl: 'templates/app-lista-spesa.html', controller: 'AppListaSpesaController' } } }) .state('app.offerte', { cache: true, url: '/offerte', views: { 'content': { templateUrl: 'templates/app-offerte.html', controller: 'AppOfferteController' } } }) .state('app.preferiti', { cache: true, url: '/preferiti', views: { 'content': { templateUrl: 'templates/app-preferiti.html', controller: 'AppPreferitiController' } } }) .state('app.impostazioni', { cache: true, url: '/impostazioni', views: { 'content': { templateUrl: 'templates/app-impostazioni.html', controller: 'AppImpostazioniController' } } }) .state('app.assistenza', { cache: true, url: '/assistenza', views: { 'content': { templateUrl: 'templates/app-assistenza.html', controller: 'AppAssistenzaController' } } }) .state('app.assistenza_tour', { cache: true, url: '/assistenza/tour', views: { 'content': { templateUrl: 'templates/app-assistenza-tour.html', controller: 'AppAssistenzaTourController' } } }) .state('app.pagina', { cache: true, url: '/pagina/:pageId', views: { 'content': { templateUrl: 'templates/app-pagina.html', controller: 'AppPaginaController' } } }) .state('app.punti_vendita', { cache: true, url: '/punti-vendita', views: { 'content': { templateUrl: 'templates/app-punti-vendita.html', controller: 'AppPuntiVenditaController' } } }) .state('app.punti_vendita_dettaglio', { cache: true, url: '/punti-vendita/:id', views: { 'content': { templateUrl: 'templates/app-punti-vendita-dettaglio.html', controller: 'AppPuntiVenditaDettaglioController' } } }) .state('app.profilo', { cache: true, url: '/profilo', views: { 'content': { templateUrl: 'templates/app-profilo.html', controller: 'AppProfiloController' } } }) .state('app.profilo_modifica', { cache: true, url: '/profilo/modifica', views: { 'content': { templateUrl: 'templates/app-profilo-modifica.html', controller: 'AppProfiloModificaController' } } }) .state('app.notifiche', { cache: true, url: '/notifiche', views: { 'content': { templateUrl: 'templates/app-notifiche.html', controller: 'AppNotificheController' } } }) .state('app.magazine', { cache: true, url: '/magazine', views: { 'content': { templateUrl: 'templates/app-magazine.html', controller: 'AppMagazineController' } } }) .state('app.landing', { cache: true, url: '/landing/:id', views: { 'content': { templateUrl: 'templates/app-landing.html', controller: 'AppLandingController' } } }) ; $urlRouterProvider.otherwise('/welcome'); }) .config(function(ImgCacheProvider, DEBUG) { ImgCacheProvider.setOptions({ debug: DEBUG ? true : false, usePersistentCache: true }); ImgCacheProvider.manualInit = true; }) .config(function($provide) { $provide.decorator('$exceptionHandler', ['$delegate', function($delegate){ return function(exception, cause){ $delegate(exception, cause); var data = { type: 'angular', url: window.location.hash, localtime: Date.now() }; if (cause) { data.cause = cause; } if (exception){ if (exception.message) { data.message = exception.message; } if (exception.name) { data.name = exception.name; } if (exception.stack) { data.stack = exception.stack; } } console.log('Exception ' + JSON.stringify(data)); }; }]); }) .config(function(ionGalleryConfigProvider) { ionGalleryConfigProvider.setGalleryConfig({ action_label: 'Chiudi', toggle: true, row_size: 3, fixed_row_size: true }); }) .run(function( //$cordovaGoogleAnalytics, $ionicHistory, $ionicPlatform, $cordovaNativeStorage, ImgCache, $rootScope, $location, $timeout, DEBUG ) { /* if (typeof window.analytics === 'undefined') { window.analytics = { startTrackerWithId: function () {}, setUserId: function () {}, trackView: function () {}, trackEvent: function () {}, debugMode: function () {} }; } */ $ionicPlatform.ready(function() { if (window.cordova && window.cordova.plugins.Keyboard) { cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); cordova.plugins.Keyboard.disableScroll(true); } if (window.navigationbar && window.navigationbar.hide) { window.navigationbar.hide(); } /* if (DEBUG) { $cordovaGoogleAnalytics.debugMode(); } $timeout(function(){ $cordovaGoogleAnalytics.startTrackerWithId('UA-91619636-2'); }, 3000); */ ImgCache.$init(); universalLinks.subscribe('landing', function (eventData) { console.log('Did launch application from the link: ' + eventData.url); //console.log(JSON.stringify(eventData)); var res = eventData.path.split("/"); res.shift(); //res.shift(); //debug if($rootScope.user) { var slug = res[1].split('?')[0]; $location.path('/app/landing/'+slug); } }); }); $ionicPlatform.registerBackButtonAction(function (event) { $ionicHistory.goBack(-1); }, 100); }) .filter('mformat', function () { return function (timeStamp, formatString) { return moment(timeStamp).format(formatString); }; }); $('body').on('click', 'a[rel=external]', function (e) { e.preventDefault(); e.stopPropagation(); var href = $(e.target).closest('a').attr('href'); if (!href) { href = $(e.target).closest('a').data('href'); } window.open(href, '_system'); }); $('body').on('click', 'a[rel=inappbrowser]', function (e) { e.preventDefault(); e.stopPropagation(); var href = $(e.target).closest('a').attr('href'); if (!href) { href = $(e.target).closest('a').data('href'); } if (cordova && cordova.InAppBrowser) { cordova.InAppBrowser.open(href, '_blank', 'closebuttoncaption=Chiudi'); } else { window.open(href, '_system'); } });