Skip to content

Commit a6d20f1

Browse files
committed
Merge pull request #8 from infomofo/rootScope
move functions from app.js to rootScope.js for clearer testing
2 parents 2a9b009 + dbfd9ab commit a6d20f1

File tree

8 files changed

+282
-215
lines changed

8 files changed

+282
-215
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ language: node_js
22
node_js:
33
- '0.10'
44
before_script:
5-
- 'npm install -g bower grunt-cli'
6-
- 'bower install'
5+
- 'npm install -g grunt-cli'

Gruntfile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ module.exports = function (grunt) {
476476
});
477477

478478
grunt.registerTask('test', [
479+
'bower:install',
479480
'clean:server',
480481
'concurrent:test',
481482
'autoprefixer',

app/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@
5555

5656
<!-- build:js({.tmp,app}) scripts/scripts.js -->
5757
<script src="scripts/app.js"></script>
58+
<script src="scripts/rootscope.js"></script>
5859
<script src="scripts/controllers/main.js"></script>
5960
<script src="scripts/controllers/about.js"></script>
60-
<script src="scripts/controllers/myroute.js"></script>
6161
<!-- endbuild -->
6262
</body>
6363
</html>

app/scripts/app.js

Lines changed: 6 additions & 208 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
'use strict';
22

3+
/**
4+
* app.js
5+
*
6+
* This file will contain the module definition, routing, and themeing for the application
7+
*/
8+
39
/**
410
* @ngdoc overview
511
* @name yoAngularCordovaApp
@@ -50,214 +56,6 @@ app
5056
});
5157
});
5258

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-
26159
app
26260
.config(function($mdThemingProvider) {
26361
$mdThemingProvider.theme('default')

0 commit comments

Comments
 (0)