|
1 | 1 | 'use strict';
|
2 | 2 |
|
| 3 | +/** |
| 4 | + * app.js |
| 5 | + * |
| 6 | + * This file will contain the module definition, routing, and themeing for the application |
| 7 | + */ |
| 8 | + |
3 | 9 | /**
|
4 | 10 | * @ngdoc overview
|
5 | 11 | * @name yoAngularCordovaApp
|
|
50 | 56 | });
|
51 | 57 | });
|
52 | 58 |
|
53 |
| -app.run(function ($rootScope, $location, $mdSidenav, $mdToast) { |
54 |
| - |
55 |
| - var searchActive = false; |
56 |
| - |
57 |
| - $rootScope.openSidenav = function() { |
58 |
| - $mdToast.hide(); |
59 |
| - console.log('toggling left'); |
60 |
| - $mdSidenav('left').open() |
61 |
| - .then(function(){ |
62 |
| - console.debug('toggle left is done'); |
63 |
| - }); |
64 |
| - }; |
65 |
| - |
66 |
| - var history = []; |
67 |
| - |
68 |
| - $rootScope.$on('$routeChangeSuccess', function() { |
69 |
| - |
70 |
| - var path = $location.$$path; |
71 |
| - //tracker.sendAppView(path); |
72 |
| - if (path !== '/') { |
73 |
| - history.push($location.$$path); |
74 |
| - } |
75 |
| - }); |
76 |
| - |
77 |
| - var disableSearch = function() { |
78 |
| - var searchBox = angular.element('#searchBox'); |
79 |
| - searchBox.blur(); |
80 |
| - searchActive = false; |
81 |
| - }; |
82 |
| - |
83 |
| - var backFunction = function() { |
84 |
| - if (searchActive) { |
85 |
| - disableSearch(); |
86 |
| - } else { |
87 |
| - var prevUrl = history.length > 1 ? history.splice(-2)[0] : '/'; |
88 |
| - $location.path(prevUrl); |
89 |
| - } |
90 |
| - }; |
91 |
| - |
92 |
| - $rootScope.backFunction = function () { |
93 |
| - backFunction(); |
94 |
| - }; |
95 |
| - |
96 |
| - var backButton = function() { |
97 |
| - backFunction(); |
98 |
| - $rootScope.$apply(); |
99 |
| - }; |
100 |
| - |
101 |
| - var onResume = function() { |
102 |
| - $rootScope.$emit('Resumed'); |
103 |
| - }; |
104 |
| - |
105 |
| - var onDeviceReady = function(){ |
106 |
| - document.addEventListener('backbutton', backButton, false); |
107 |
| - document.addEventListener('resume', onResume, false); |
108 |
| - document.addEventListener('online', onResume, false); |
109 |
| - // detect application touches and emit an event on rootscope: |
110 |
| - window.addEventListener('statusTap', function() { |
111 |
| - $rootScope.$emit('NavClicked'); |
112 |
| - }); |
113 |
| - }; |
114 |
| - document.addEventListener('deviceready', onDeviceReady, false); |
115 |
| - |
116 |
| - /** |
117 |
| - * Clears the known history |
118 |
| - */ |
119 |
| - $rootScope.clearHistory = function() { |
120 |
| - history = []; |
121 |
| - }; |
122 |
| - |
123 |
| - /** |
124 |
| - * Returns if there is no history left to return to |
125 |
| - * @returns {boolean} |
126 |
| - */ |
127 |
| - $rootScope.isHistoryEmpty = function() { |
128 |
| - return history.length <= 1; |
129 |
| - }; |
130 |
| - |
131 |
| - /** |
132 |
| - * Returns if there is eligible history to go back to |
133 |
| - * @returns {boolean} |
134 |
| - */ |
135 |
| - $rootScope.isHistory = function() { |
136 |
| - return history.length > 1; |
137 |
| - }; |
138 |
| - |
139 |
| - /** |
140 |
| - * Closes the mdSidenav and handles any related behavior |
141 |
| - */ |
142 |
| - $rootScope.closeSideNav = function(){ |
143 |
| - $mdSidenav('left').close() |
144 |
| - .then(function(){ |
145 |
| - //console.debug("toggle left is done"); |
146 |
| - }); |
147 |
| - }; |
148 |
| - |
149 |
| - /** |
150 |
| - * A replacement for the sidenav toggle button if it is replaced with a hamburger action. |
151 |
| - */ |
152 |
| - $rootScope.handleHamburger = function() { |
153 |
| - if ($rootScope.isHistoryEmpty()) { |
154 |
| - $rootScope.toggleSideNav(); |
155 |
| - } else { |
156 |
| - $rootScope.backFunction(true); |
157 |
| - } |
158 |
| - }; |
159 |
| - |
160 |
| - /** |
161 |
| - * This function should be called to change views- this will retain history and encapsulate any other behaviors. |
162 |
| - * @param url |
163 |
| - */ |
164 |
| - $rootScope.go = function (url) { |
165 |
| - // Hide any active toasts when the route changes |
166 |
| - $mdToast.hide(); |
167 |
| - |
168 |
| - $rootScope.closeSideNav(); |
169 |
| - $location.path(url); |
170 |
| - }; |
171 |
| - |
172 |
| - /** |
173 |
| - * Handles the event of clicking on the nav bar- this is a common application convention that will make the active |
174 |
| - * scrollable container scroll to the top. |
175 |
| - */ |
176 |
| - $rootScope.$on('NavClicked', function() { |
177 |
| - var domElement = document.getElementById('scrollcontainer'); |
178 |
| - domElement.style.overflow = 'hidden'; |
179 |
| - // wait for any current momentum scrolling to finish and then jump to top |
180 |
| - //$('#scrollcontainer').animate({scrollTop: 0}, 'fast'); |
181 |
| - domElement.style.overflow = ''; |
182 |
| - }); |
183 |
| - |
184 |
| - /** |
185 |
| - * Displays the search box element on the toolbar |
186 |
| - */ |
187 |
| - $rootScope.showSearch = function() { |
188 |
| - var searchBox = angular.element('#searchBox'); |
189 |
| - searchBox.focus(); |
190 |
| - }; |
191 |
| - |
192 |
| - /** |
193 |
| - * Displays an alert toast in the bottom right that disappears after 3 seconds |
194 |
| - * |
195 |
| - * Suitable for displaying short unactionable messages to the user |
196 |
| - * |
197 |
| - * @param message The alert message to display to the user |
198 |
| - */ |
199 |
| - $rootScope.showAlertToast = function(message) { |
200 |
| - var toast = $mdToast.simple() |
201 |
| - .content(message) |
202 |
| - .highlightAction(false) |
203 |
| - .position('bottom right') |
204 |
| - .hideDelay(2000); |
205 |
| - $mdToast.show(toast); |
206 |
| - }; |
207 |
| - |
208 |
| - /** |
209 |
| - * Displays an alert toast in the bottom right that disappears when dismissed by the user |
210 |
| - * |
211 |
| - * Suitable for displaying short unactionable messages to the user |
212 |
| - * |
213 |
| - * @param message The alert message to display to the user |
214 |
| - */ |
215 |
| - $rootScope.showAlertToastPersistent = function(message) { |
216 |
| - var toast = $mdToast.simple() |
217 |
| - .content(message) |
218 |
| - .highlightAction(false) |
219 |
| - .position('bottom right') |
220 |
| - .hideDelay(0); |
221 |
| - $mdToast.show(toast); |
222 |
| - }; |
223 |
| - |
224 |
| - /** |
225 |
| - * Displays an undoable toast in the bottom right that disappears after 3 seconds |
226 |
| - * |
227 |
| - * @param message the message to display to the user |
228 |
| - * @param callback the function to call when the undo action is clicked |
229 |
| - */ |
230 |
| - $rootScope.showUndoToast = function(message, callback) { |
231 |
| - var toast = $mdToast.simple() |
232 |
| - .content(message) |
233 |
| - .action('undo') |
234 |
| - .highlightAction(false) |
235 |
| - .position('bottom right') |
236 |
| - .hideDelay(2000); |
237 |
| - $mdToast.show(toast).then(function() { |
238 |
| - callback(true); |
239 |
| - }); |
240 |
| - }; |
241 |
| - |
242 |
| - /** |
243 |
| - * Displays an undoable toast in the bottom right that disappears when dismissed by the user |
244 |
| - * |
245 |
| - * @param message the message to display to the user |
246 |
| - * @param callback the function to call when the undo action is clicked |
247 |
| - */ |
248 |
| - $rootScope.showUndoToastPersistent = function(message, callback) { |
249 |
| - var toast = $mdToast.simple() |
250 |
| - .content(message) |
251 |
| - .action('undo') |
252 |
| - .highlightAction(false) |
253 |
| - .position('bottom right') |
254 |
| - .hideDelay(0); |
255 |
| - $mdToast.show(toast).then(function() { |
256 |
| - callback(true); |
257 |
| - }); |
258 |
| - }; |
259 |
| -}); |
260 |
| - |
261 | 59 | app
|
262 | 60 | .config(function($mdThemingProvider) {
|
263 | 61 | $mdThemingProvider.theme('default')
|
|
0 commit comments