-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrick.js
executable file
·117 lines (102 loc) · 2.95 KB
/
trick.js
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
/* global firebase, angular */
'use strict'
var config = {
apiKey: 'AIzaSyD07mROu__kGOuJ-0MyjtjS6R5-DiTfUpM',
authDomain: 'project-5641153190345267944.firebaseapp.com',
databaseURL: 'https://project-5641153190345267944.firebaseio.com',
projectId: 'project-5641153190345267944',
storageBucket: 'project-5641153190345267944.appspot.com',
messagingSenderId: '1048157266079'
}
firebase.initializeApp(config)
const firestore = firebase.firestore()
const settings = { timestampsInSnapshots: true }
firestore.settings(settings)
function toggleNav () { // eslint-disable-line
document.getElementsByClassName('topnav')[0].classList.toggle('responsive')
document.getElementsByTagName('nav')[0].classList.toggle('responsive')
}
angular.module('trick', [
'ngRoute',
'trick.contact',
'trick.translate',
'trick.levels',
'firebase',
'hc.marked'
])
.config([
'$locationProvider', '$routeProvider',
function ($locationProvider, $routeProvider) {
$locationProvider.html5Mode(true)
.hashPrefix('!')
$routeProvider.otherwise({
redirectTo: '/'
})
}
])
.factory('Auth', [
'$firebaseAuth',
function ($firebaseAuth) {
return $firebaseAuth()
}
])
.factory('Db',
function () {
return firebase.database()
.ref()
})
.run(function ($location, $rootScope, Auth, Db) {
$rootScope.$on('$routeChangeError', function (event, next, previous, error) {
if (error === 'AUTH_REQUIRED') {
$location.path('/')
$rootScope.Error(
'You need to be signed in to access this page, please Sign In and try again.'
)
}
})
$rootScope.signIn = function () {
$rootScope.user = null
$rootScope.Error('', false)
Auth.$signInWithPopup('google')
.then(function (firebaseUser) {
$rootScope.user = firebaseUser
})
.catch(function (error) {
$rootScope.Error(error)
})
}
$rootScope.signOut = function () {
Auth.$signOut()
}
$rootScope.goHome = function () {
$location.path('/')
}
$rootScope.Error = function (e, bool) {
$rootScope.error = {
text: e,
show: (bool === undefined ? true : bool)
}
}
$rootScope.Subpage = function (name) {
$rootScope.subpage = name
}
Auth.$onAuthStateChanged(function (firebaseUser) {
$rootScope.user = firebaseUser
$rootScope.admin = ($rootScope.user && ($rootScope.user.uid === 'Kpz3afszjBR0qwZYUrKURRJx2cm2' || $rootScope.user.uid === 'g0G3A7FxieN333lZ2RKclkmv9Uw1'))
})
})
.directive('ngConfirmClick', [
function () {
return {
link: function (scope, element, attr) {
var msg = attr.ngConfirmClick || 'Are you sure?'
var clickAction = attr.confirmedClick
element.bind('click', function (event) {
if (window.confirm(msg)) {
scope.$eval(clickAction)
}
})
}
}
}
])