-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
142 lines (126 loc) · 4.18 KB
/
app.js
File metadata and controls
142 lines (126 loc) · 4.18 KB
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
140
141
142
// Ionic Starter App
// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
angular.module('starter', ['ionic'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
})
.controller('MainCtrl', function($scope, $ionicGesture) {
// RAPID TEST - hence not the Angular way. This brute manipulation is here in the controller to test the speed of velocity.js within Ionic
var isFwd = false;
var win_height = window.innerHeight;
var container = angular.element(document.querySelector('#container'));
var bg_dof = angular.element(document.querySelector('.bg_dof'));
$scope.y = 0;
$scope.ny = 0;
// These listeners could be registered like the multitouch one above. Here, testing the other way; from the html element itself. Most gestures are available this way - only multitouch events seem to be missing for some reason.
$scope.onTouch = function(e){Velocity.mock = true;}
$scope.onRelease = function(e){
Velocity.mock = false;
if($scope.ny > -(win_height/2)) {
$scope.ny = 0;
} else if($scope.ny < -(win_height/2)) {
$scope.ny = -win_height+100;
}
$scope.decelerate();
}
$scope.onDrag = function(ev){
Velocity.mock = true;
$scope.ny = $scope.y + ev.gesture.deltaY;
Velocity(container, {
translateY: $scope.ny
});
$scope.velocityY = ($scope.ny - $scope.lastY);
$scope.lastY = $scope.ny;
var dof_opacity = ($scope.ny-0)/(-win_height-1) * (1-0) + 0;
Velocity(bg_dof, {
opacity: dof_opacity
});
if($scope.ny > -(win_height/2)) {
document.getElementById( 'to_splash' ).style.display = 'none';
document.getElementById( 'to_menu' ).style.display = 'block';
} else if($scope.ny < -(win_height/2)) {
document.getElementById( 'to_splash' ).style.display = 'block';
document.getElementById( 'to_menu' ).style.display = 'none';
}
}
$scope.decelerate = function(){
$scope.y = $scope.ny;
Velocity(container, {
translateY: $scope.y
}, [200, 20]);
var dof_opacity = ($scope.ny-0)/(-win_height-1) * (1-0) + 0;
Velocity(bg_dof, {
opacity: dof_opacity
}, {duration: 100});
return;
}
// Animate full movement
$scope.toggle = function(){
if(isFwd) $scope.reverse()
else $scope.play();
}
$scope.play= function(){
$scope.y = -win_height;
$scope.ny = -win_height;
$scope.stop();
isFwd = true;
Velocity(container, {
translateY: -win_height+100,
}, [200, 20]);
var dof_opacity = ($scope.ny-0)/(-win_height-1) * (1-0) + 0;
Velocity(bg_dof, {
opacity: dof_opacity
}, {duration: 100});
document.getElementById( 'to_splash' ).style.display = 'block';
document.getElementById( 'to_menu' ).style.display = 'none';
}
$scope.stop= function(){
isFwd = false;
Velocity(container, "stop");
}
$scope.reverse= function(){
$scope.y = 0;
$scope.ny = 0;
$scope.stop();
Velocity(container, {
translateY: "0px"
}, [200, 20]);
var dof_opacity = ($scope.ny-0)/(-win_height-1) * (1-0) + 0;
Velocity(bg_dof, {
opacity: dof_opacity
}, {duration: 100});
document.getElementById( 'to_splash' ).style.display = 'none';
document.getElementById( 'to_menu' ).style.display = 'block';
}
$scope.page = function(i) {
console.log(i);
var page = angular.element(document.querySelector('#page_'+ i));
Velocity(page, {
left: 0
}, {
display: 'block',
easing: [200, 20]
});
}
$scope.back = function(i) {
console.log(i);
var page = angular.element(document.querySelector('#page_'+ i));
Velocity(page, {
left: '100%'
}, {
display: 'none',
easing: [200, 20]
});
}
});