From 9f341a8ccb3829ccb5a02797bd44ec301f6bb14f Mon Sep 17 00:00:00 2001 From: Eric Svensson Date: Thu, 16 Jul 2015 15:38:11 +0200 Subject: [PATCH] Stopped ion-spinner Android animation script from running indefinitely. --- js/angular/controller/spinnerController.js | 15 +++++++++++++-- js/angular/directive/spinner.js | 5 +++++ js/angular/service/loading.js | 2 ++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/js/angular/controller/spinnerController.js b/js/angular/controller/spinnerController.js index 03a2bded3b0..0c2a3a76c0e 100644 --- a/js/angular/controller/spinnerController.js +++ b/js/angular/controller/spinnerController.js @@ -330,6 +330,10 @@ var animations = { android: function(ele) { + var self = this; + + this.stop = false; + var rIndex = 0; var rotateCircle = 0; var startTime; @@ -337,6 +341,8 @@ var circleEle = ele.querySelector('circle'); function run() { + if (self.stop) return; + var v = easeInOutCubic(Date.now() - startTime, 650); var scaleX = 1; var translateX = 0; @@ -372,6 +378,7 @@ return function() { startTime = Date.now(); run(); + return self; }; } @@ -392,7 +399,7 @@ '$attrs', '$ionicConfig', function($element, $attrs, $ionicConfig) { - var spinnerName; + var spinnerName, anim; this.init = function() { spinnerName = $attrs.icon || $ionicConfig.spinner.icon(); @@ -415,7 +422,11 @@ }; this.start = function() { - animations[spinnerName] && animations[spinnerName]($element[0])(); + animations[spinnerName] && (anim = animations[spinnerName]($element[0])()); + }; + + this.stop = function() { + animations[spinnerName] && (anim.stop = true); }; }]); diff --git a/js/angular/directive/spinner.js b/js/angular/directive/spinner.js index 471264d7db3..1c4e15927c9 100644 --- a/js/angular/directive/spinner.js +++ b/js/angular/directive/spinner.js @@ -188,6 +188,11 @@ IonicModule link: function($scope, $element, $attrs, ctrl) { var spinnerName = ctrl.init(); $element.addClass('spinner spinner-' + spinnerName); + + $element.on('$destroy', function onDestroy() + { + ctrl.stop(); + }); } }; }); diff --git a/js/angular/service/loading.js b/js/angular/service/loading.js index 9223089079b..163e70df8e6 100644 --- a/js/angular/service/loading.js +++ b/js/angular/service/loading.js @@ -183,6 +183,8 @@ function($ionicLoadingConfig, $ionicBody, $ionicTemplateLoader, $ionicBackdrop, } $timeout.cancel(self.durationTimeout); self.isShown = false; + var loading = self.element.children(); + loading.html(""); }; return self;