{"size": 3797, "ext": "js", "max_stars_repo_path": "app/js/app.js", "max_stars_repo_name": "nqdy666/qjzdclub-ionic", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "app/js/app.js", "max_issues_repo_name": "nqdy666/qjzdclub-ionic", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "app/js/app.js", "max_forks_repo_name": "nqdy666/qjzdclub-ionic", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 23.8805031447, "max_line_length": 100, "alphanum_fraction": 0.5636028444}
'use strict';

// Ionic cnodejs App
angular.module('cnodejs', [
  'ionic',
  'angularMoment',
  'cnodejs.controllers',
  'cnodejs.filters',
  'cnodejs.directives',
  'cnodejs.config']
)

.run(function($ionicPlatform, $log, $timeout, $state, $rootScope, amMoment, ENV, Push, User) {

  // set moment locale
  amMoment.changeLocale('zh-cn');

  // notify
  if (!navigator.notification) {
    navigator.notification = {
      alert: function(message) {
        window.alert(message);
      }
    };
  }

  // push notification callback
  var notificationCallback = function(data, isActive) {
    $log.debug(data);
    var notif = angular.fromJson(data);
    if (notif.extras) {
      // android
      if (notif.extras['cn.jpush.android.EXTRA']['topicId']) {
        $state.go('app.topic', {
          id: notif.extras['cn.jpush.android.EXTRA']['topicId']
        });
      } else {
        $state.go('app.messages');
      }
    } else {
      // ios
      if (notif.topicId) {
        if (isActive) {
          $rootScope.getMessageCount();
        } else {
          $state.go('app.topic', {
            id: notif.topicId
          });
        }
      } else {
        $state.go('app.messages');
      }
    }
  };
  $ionicPlatform.ready(function() {
    if(window.cordova) {

      // setup google analytics
      if (window.analytics && ENV.name === 'production') {
        window.analytics.startTrackerWithId('UA-57246029-1');
      }

      // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
      // for form inputs)
      if (window.cordova.plugins.Keyboard) {
        cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
        cordova.plugins.Keyboard.disableScroll(true);
      }
    }

    // push handler
    Push.init(notificationCallback);

    // detect current user have not set alias of jpush
    var currentUser = User.getCurrentUser();
    if (currentUser.id) {
      Push.setAlias(currentUser.id);
    }

    if (navigator.splashscreen) {
      $timeout(function() {
        navigator.splashscreen.hide();

        // check if have push after app launch
        Push.check();
      }, 100);
    } else {
      $log.debug('no splash screen plugin');
    }

  });

})
.config(function(ENV, $stateProvider, $urlRouterProvider, $logProvider) {

  $logProvider.debugEnabled(ENV.debug);
  $stateProvider
    .state('app', {
      url: '',
      abstract: true,
      templateUrl: 'templates/menu.html',
      controller: 'AppCtrl'
    })
    .state('app.user', {
      url: '/user/:loginname',
      views: {
        'menuContent': {
          templateUrl: 'templates/user.html',
          controller: 'UserCtrl'
        }
      }
    })
    .state('app.messages', {
      url: '/my/messages',
      views: {
        'menuContent': {
          templateUrl: 'templates/messages.html',
          controller: 'MessagesCtrl'
        }
      }
    })
    .state('app.topics', {
      url: '/topics/:tab',
      views: {
        'menuContent': {
          templateUrl: 'templates/topics.html',
          controller: 'TopicsCtrl'
        }
      }
    })
    .state('app.topic', {
      url: '/topic/:id',
      views: {
        'menuContent': {
          templateUrl: 'templates/topic.html',
          controller: 'TopicCtrl'
        }
      }
    })
    .state('app.settings', {
      url: '/settings',
      views: {
        'menuContent': {
          templateUrl: 'templates/settings.html',
          controller: 'SettingsCtrl'
        }
      }
    });
  $urlRouterProvider.otherwise('/topics/all');
});

angular.module('cnodejs.controllers', ['cnodejs.services']);

angular.module('cnodejs.services', ['ngResource', 'cnodejs.config']);

angular.module('cnodejs.filters', ['cnodejs.services']);

angular.module('cnodejs.directives', []);
