From cf338cf2c8b1ab6dc83f9cdc4525c04350952ce1 Mon Sep 17 00:00:00 2001 From: Mike Peters Date: Fri, 12 Jun 2015 15:36:59 -0500 Subject: [PATCH] feat(spinner): Allow ionSpinner default to be set by ionicConfigProvider Closes #3877 --- js/angular/controller/spinnerController.js | 16 ++++----------- js/angular/service/ionicConfig.js | 22 +++++++++++++++++++++ test/html/spinners.html | 11 ++++++++--- test/unit/angular/directive/spinner.js | 23 ++++++++++++++++++++++ 4 files changed, 57 insertions(+), 15 deletions(-) create mode 100644 test/unit/angular/directive/spinner.js diff --git a/js/angular/controller/spinnerController.js b/js/angular/controller/spinnerController.js index 13be7ee4145..03a2bded3b0 100644 --- a/js/angular/controller/spinnerController.js +++ b/js/angular/controller/spinnerController.js @@ -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', { diff --git a/js/angular/service/ionicConfig.js b/js/angular/service/ionicConfig.js index 8a0f07718dd..3c172a4a834 100644 --- a/js/angular/service/ionicConfig.js +++ b/js/angular/service/ionicConfig.js @@ -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 @@ -253,6 +261,9 @@ IonicModule scrolling: { jsScrolling: PLATFORM }, + spinner: { + icon: PLATFORM + }, tabs: { style: PLATFORM, position: PLATFORM @@ -300,6 +311,10 @@ IonicModule jsScrolling: true }, + spinner: { + icon: 'ios' + }, + tabs: { style: 'standard', position: 'bottom' @@ -345,6 +360,10 @@ IonicModule toggle: 'small' }, + spinner: { + icon: 'android' + }, + tabs: { style: 'striped', position: 'top' @@ -358,6 +377,9 @@ IonicModule //scrolling: { // jsScrolling: false //} + spinner: { + icon: 'android' + } }); diff --git a/test/html/spinners.html b/test/html/spinners.html index bbdad24e604..f376070759c 100644 --- a/test/html/spinners.html +++ b/test/html/spinners.html @@ -1,5 +1,5 @@ - + Spinners @@ -7,7 +7,7 @@ - + >

Spinners

@@ -124,6 +124,11 @@

Spinners

- + diff --git a/test/unit/angular/directive/spinner.js b/test/unit/angular/directive/spinner.js new file mode 100644 index 00000000000..62f215ae11f --- /dev/null +++ b/test/unit/angular/directive/spinner.js @@ -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('')(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('')(scope); + expect(el.is('.spinner-android')).toEqual(true); + })); + +});