Git Repository Public Repository

YouAndWeb_TwoToc

URLs

Copy to Clipboard
 
a98e8d4c8be3c9266abcdd007f47a6b1c3ed9599
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
'use strict';

angular.module('dashboardApp', [
  'ngCookies',
  'ngResource',
  'ngSanitize',
  'ui.router',
  'ui.bootstrap',
  'pascalprecht.translate'
])
  .config(function($stateProvider, $urlRouterProvider, $locationProvider, $httpProvider, $translateProvider) {
    $urlRouterProvider
      .otherwise('/');

    $locationProvider.html5Mode(true);
    $httpProvider.interceptors.push('authInterceptor');

    $translateProvider.useLoaderCache(true).useStaticFilesLoader({
      prefix: 'assets/langs/locale-',
      suffix: '.json'
    })
    .useCookieStorage()
    .storagePrefix('twotoc_')
    .useSanitizeValueStrategy('sanitize')
    .preferredLanguage('it');
  })

  .factory('authInterceptor', function($rootScope, $q, $cookies, $injector) {
    var state;
    return {
      // Add authorization token to headers
      request: function(config) {
        config.headers = config.headers || {};
        if ($cookies.get('token')) {
          config.headers.Authorization = 'Bearer ' + $cookies.get('token');
        }
        return config;
      },

      // Intercept 401s and redirect you to login
      responseError: function(response) {
        if (response.status === 401) {
          (state || (state = $injector.get('$state'))).go('login');
          // remove any stale tokens
          $cookies.remove('token');
          return $q.reject(response);
        }
        else {
          return $q.reject(response);
        }
      }
    };
  })

  .directive('resizewin', ['$window', function($window) {
    return function (scope) {
      var w = angular.element($window);
      scope.getWindowDimensions = function () {
          return {
              'h': w.height(),
              'w': w.width()
          };
      };
      scope.$watch(scope.getWindowDimensions, function (newValue) {
          scope.windowHeight = newValue.h;
          scope.windowWidth = newValue.w;

          scope.style = function (offset) {
              return {
                  'height': (newValue.h - offset) + 'px'
                      // 'width': (newValue.w - 100) + 'px'
              };
          };

      }, true);

      w.bind('resize', function () {
          scope.$apply();
      });
    };
  }])
/*
  .directive('mratio', ['$window',  function($window) {
      return {
        restrict: 'A',
        link: function(scope, element, attrs) {

          var w = angular.element($window);
          scope.getWindowDimensions = function () {
              return {
                  'w': element.width()
              };
          };

          scope.$watch(scope.getWindowDimensions, function (newValue, oldValue) {
            mRatio(scope, element, attrs);
          });

          mRatio(scope, element, attrs);

          function mRatio(scope, element, attrs) {
            var image = new Image(); // or document.createElement('img')
            var el_width, el_height, width, height, ratio;
            el_width = element.width();
            el_height = element.height();
            image.onload = function() {
              width = this.width;
              height = this.height;
              ratio = el_width / width;
              var r_height = height * ratio;
              if (el_height / height != ratio) {
                attrs.$set('style', 'height: ' + r_height + 'px');
              }
            };
            image.src = attrs.src;
          }
        }
      }
    }])
*/
  .run(function($rootScope, $state, Auth) {
    // Redirect to login if route requires auth and the user is not logged in
    $rootScope.$on('$stateChangeStart', function(event, next) {
      if (next.authenticate) {
        Auth.isLoggedIn(function(loggedIn) {
          if (!loggedIn) {
            event.preventDefault();
            $state.go('login');
          }
        });
      }
    });
  });

Commits for YouAndWeb_TwoToc/client/app/app.js

Diff revisions: vs.
Revision Author Commited Message
a2ecfb ... PTKDev Fri 20 Nov, 2015 11:22:35 +0000

TwoToc code