Skip to content

Commit

Permalink
feat(spinner): Allow ionSpinner default to be set by ionicConfigProvi…
Browse files Browse the repository at this point in the history
…der Closes ionic-team#3877
  • Loading branch information
mikejpeters authored and perrygovier committed Jun 12, 2015
1 parent 42ed212 commit cf338cf
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 15 deletions.
16 changes: 4 additions & 12 deletions js/angular/controller/spinnerController.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,20 +390,12 @@
.controller('$ionicSpinner', [
'$element',
'$attrs',
function($element, $attrs) {
var spinnerName, spinner;
'$ionicConfig',
function($element, $attrs, $ionicConfig) {
var spinnerName;

this.init = function() {
var override = null;
if (ionic.Platform.platform() === 'windowsphone') {
override = 'android';
}
spinnerName = $attrs.icon || override || ionic.Platform.platform();
spinner = spinners[spinnerName];
if (!spinner) {
spinnerName = 'ios';
spinner = spinners.ios;
}
spinnerName = $attrs.icon || $ionicConfig.spinner.icon();

var container = document.createElement('div');
createSvgElement('svg', {
Expand Down
22 changes: 22 additions & 0 deletions js/angular/service/ionicConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@
* @returns {string}
*/

/**
* @ngdoc method
* @name $ionicConfigProvider#spinner.icon
* @description Spinner icon.
* @param {string} value
* @returns {string}
*/

/**
* @ngdoc method
* @name $ionicConfigProvider#tabs.style
Expand Down Expand Up @@ -253,6 +261,9 @@ IonicModule
scrolling: {
jsScrolling: PLATFORM
},
spinner: {
icon: PLATFORM
},
tabs: {
style: PLATFORM,
position: PLATFORM
Expand Down Expand Up @@ -300,6 +311,10 @@ IonicModule
jsScrolling: true
},

spinner: {
icon: 'ios'
},

tabs: {
style: 'standard',
position: 'bottom'
Expand Down Expand Up @@ -345,6 +360,10 @@ IonicModule
toggle: 'small'
},

spinner: {
icon: 'android'
},

tabs: {
style: 'striped',
position: 'top'
Expand All @@ -358,6 +377,9 @@ IonicModule
//scrolling: {
// jsScrolling: false
//}
spinner: {
icon: 'android'
}
});


Expand Down
11 changes: 8 additions & 3 deletions test/html/spinners.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<!DOCTYPE html>
<html ng-app="ionic">
<html ng-app="ionic.example">
<head>
<meta charset="utf-8">
<title>Spinners</title>
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
<link rel="stylesheet" href="../../../../dist/css/ionic.css">
<script src="../../../../dist/js/ionic.bundle.js"></script>
</head>
<body>
<body ng-controller="SpinnerCtrl">>

<header class="bar bar-header bar-royal">
<h1 class="title">Spinners</h1>
Expand Down Expand Up @@ -124,6 +124,11 @@ <h1 class="title">Spinners</h1>
</tbody></table>

</ion-content>

<script>
angular.module('ionic.example', ['ionic'])
.controller('SpinnerCtrl', function($scope, $ionicConfig) {
//$ionicConfig.spinner.icon('lines');
});
</script>
</body>
</html>
23 changes: 23 additions & 0 deletions test/unit/angular/directive/spinner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
describe('Ionic Spinner', function() {
var el, scope, compile;

beforeEach(module('ionic'));

beforeEach(inject(function($compile, $rootScope) {
compile = $compile;
scope = $rootScope;
}));

it('should compile and output an svg', function() {
el = compile('<ion-spinner>')(scope);
var spinner = el.find('svg');
expect(spinner.length).toEqual(1);
});

it('should add config setting class', inject(function($ionicConfig){
$ionicConfig.spinner.icon('android');
el = compile('<ion-spinner>')(scope);
expect(el.is('.spinner-android')).toEqual(true);
}));

});

0 comments on commit cf338cf

Please sign in to comment.