Skip to content

Commit cf338cf

Browse files
mikejpetersperrygovier
authored andcommitted
feat(spinner): Allow ionSpinner default to be set by ionicConfigProvider Closes #3877
1 parent 42ed212 commit cf338cf

File tree

4 files changed

+57
-15
lines changed

4 files changed

+57
-15
lines changed

js/angular/controller/spinnerController.js

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -390,20 +390,12 @@
390390
.controller('$ionicSpinner', [
391391
'$element',
392392
'$attrs',
393-
function($element, $attrs) {
394-
var spinnerName, spinner;
393+
'$ionicConfig',
394+
function($element, $attrs, $ionicConfig) {
395+
var spinnerName;
395396

396397
this.init = function() {
397-
var override = null;
398-
if (ionic.Platform.platform() === 'windowsphone') {
399-
override = 'android';
400-
}
401-
spinnerName = $attrs.icon || override || ionic.Platform.platform();
402-
spinner = spinners[spinnerName];
403-
if (!spinner) {
404-
spinnerName = 'ios';
405-
spinner = spinners.ios;
406-
}
398+
spinnerName = $attrs.icon || $ionicConfig.spinner.icon();
407399

408400
var container = document.createElement('div');
409401
createSvgElement('svg', {

js/angular/service/ionicConfig.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,14 @@
138138
* @returns {string}
139139
*/
140140

141+
/**
142+
* @ngdoc method
143+
* @name $ionicConfigProvider#spinner.icon
144+
* @description Spinner icon.
145+
* @param {string} value
146+
* @returns {string}
147+
*/
148+
141149
/**
142150
* @ngdoc method
143151
* @name $ionicConfigProvider#tabs.style
@@ -253,6 +261,9 @@ IonicModule
253261
scrolling: {
254262
jsScrolling: PLATFORM
255263
},
264+
spinner: {
265+
icon: PLATFORM
266+
},
256267
tabs: {
257268
style: PLATFORM,
258269
position: PLATFORM
@@ -300,6 +311,10 @@ IonicModule
300311
jsScrolling: true
301312
},
302313

314+
spinner: {
315+
icon: 'ios'
316+
},
317+
303318
tabs: {
304319
style: 'standard',
305320
position: 'bottom'
@@ -345,6 +360,10 @@ IonicModule
345360
toggle: 'small'
346361
},
347362

363+
spinner: {
364+
icon: 'android'
365+
},
366+
348367
tabs: {
349368
style: 'striped',
350369
position: 'top'
@@ -358,6 +377,9 @@ IonicModule
358377
//scrolling: {
359378
// jsScrolling: false
360379
//}
380+
spinner: {
381+
icon: 'android'
382+
}
361383
});
362384

363385

test/html/spinners.html

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<!DOCTYPE html>
2-
<html ng-app="ionic">
2+
<html ng-app="ionic.example">
33
<head>
44
<meta charset="utf-8">
55
<title>Spinners</title>
66
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
77
<link rel="stylesheet" href="../../../../dist/css/ionic.css">
88
<script src="../../../../dist/js/ionic.bundle.js"></script>
99
</head>
10-
<body>
10+
<body ng-controller="SpinnerCtrl">>
1111

1212
<header class="bar bar-header bar-royal">
1313
<h1 class="title">Spinners</h1>
@@ -124,6 +124,11 @@ <h1 class="title">Spinners</h1>
124124
</tbody></table>
125125

126126
</ion-content>
127-
127+
<script>
128+
angular.module('ionic.example', ['ionic'])
129+
.controller('SpinnerCtrl', function($scope, $ionicConfig) {
130+
//$ionicConfig.spinner.icon('lines');
131+
});
132+
</script>
128133
</body>
129134
</html>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
describe('Ionic Spinner', function() {
2+
var el, scope, compile;
3+
4+
beforeEach(module('ionic'));
5+
6+
beforeEach(inject(function($compile, $rootScope) {
7+
compile = $compile;
8+
scope = $rootScope;
9+
}));
10+
11+
it('should compile and output an svg', function() {
12+
el = compile('<ion-spinner>')(scope);
13+
var spinner = el.find('svg');
14+
expect(spinner.length).toEqual(1);
15+
});
16+
17+
it('should add config setting class', inject(function($ionicConfig){
18+
$ionicConfig.spinner.icon('android');
19+
el = compile('<ion-spinner>')(scope);
20+
expect(el.is('.spinner-android')).toEqual(true);
21+
}));
22+
23+
});

0 commit comments

Comments
 (0)