-
Notifications
You must be signed in to change notification settings - Fork 0
/
oli.js
139 lines (129 loc) · 3.76 KB
/
oli.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
(function(angular){
'use strict' //ECMA5 strict mode
var baseUrl = '/';
String.prototype.capitalize = function() {
return this.charAt(0).toUpperCase() + this.slice(1);
}
var oli = angular.module('Oli',['ngRoute']);
oli.config(function($routeProvider, $locationProvider, $httpProvider){
$locationProvider.html5Mode(true);
$routeProvider
.when(baseUrl, {
templateUrl: 'views/homepage/homepage.html',
controllerAs: 'ctrl',
controller: function($rootScope, $log){
var ctrl = this;
$rootScope.pageTitle = ' - Home';
ctrl.pageClass = "appear";
}
})
.when(baseUrl + "about", {
templateUrl: baseUrl + 'views/about/about.html',
controllerAs: 'ctrl',
controller: function($rootScope, $log){
var ctrl = this;
$rootScope.pageTitle = ' - About';
ctrl.pageClass = "appear";
}
})
.when(baseUrl + "projects", {
templateUrl: baseUrl + 'views/projects/projects.html',
controllerAs: 'ctrl',
controller: function($rootScope){
var ctrl= this;
$rootScope.pageTitle = ' - Projects';
ctrl.pageClass = "appear";
}
})
.when(baseUrl + "blog", {
templateUrl: baseUrl + 'views/blog/blog.html',
controllerAs: 'ctrl',
controller: function($rootScope){
var ctrl= this;
$rootScope.pageTitle = ' - I\'m Crazy!';
ctrl.pageClass = "appear";
}
})
.when(baseUrl + "about/:what", {
templateUrl: function(url){
return baseUrl + 'views/about/' + url.what + "/" + url.what + '.html';
},
controllerAs: 'ctrl',
controller: function($rootScope, $routeParams){
var ctrl=this;
$rootScope.pageTitle = ' - ' + $routeParams.what.capitalize();
ctrl.pageClass = "appear";
}
})
.when(baseUrl + "projects/:which", {
templateUrl: function(url){
return baseUrl + 'views/projects/' + url.which + "/" + url.which + '.html';
},
controllerAs: 'ctrl',
controller: function($rootScope, $routeParams){
var ctrl=this;
$rootScope.pageTitle = ' - ' + $routeParams.which;
ctrl.pageClass = "appear";
}
})
.otherwise({
redirectTo : baseUrl
});
});
oli.run(function($rootScope, $log){
//This would be better as a component, but that will come later
var musicVolume = 1.0
$rootScope.isPlaying = false;
var loadedHowler = false;
var homeMusic;
$rootScope.$on("$routeChangeSuccess", function(event, next, current) {
// $log.log(document.location.href);
gtag('config', 'UA-93236516-3', {'page_path': document.location.href});
});
$rootScope.toggleMusic = function(){
if(!loadedHowler){
$rootScope.isPlaying = true;
$.getScript("/dependencies/howlerjs/howler.core.min.js", function(){
loadedHowler = true;
homeMusic = new Howl({
src: ['/music/Newbie Melody (Old Music).mp3'],
volume: musicVolume,
loop: true,
html5: true,
autoplay: true
});
});
return;
}
if($rootScope.isPlaying){
// homeMusic.once('fade', homeMusic.pause());
// the above should work but cuts off nastily, probably some bug
$rootScope.isPlaying = false
homeMusic.fade(musicVolume,0.0,0.4);
window.setTimeout(function(){homeMusic.pause();},300);
}
else {
$rootScope.isPlaying = true;
homeMusic.once('fade', homeMusic.play());
homeMusic.fade(0.0,musicVolume,0.4);
// homeMusic.play();
}
}
function moveBox(event, next, current) {
var dist,width;
$(".main-nav-item").each(function(){
if(window.location.href === this.href){
dist = $(this).offset().left - currLink.offset().left - 3;
width = parseInt($(this).css('width'))+6;
}
});
if(!dist){
return;
}
currLink.css('left',"+="+dist.toString());
currLink.css('width',width.toString()+"px");
}
var currLink = $('#current-link-box');
$rootScope.$on("$routeChangeSuccess", moveBox);
});
}(window.angular))