mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
@@ -1,55 +0,0 @@
|
||||
/**
|
||||
* Stop race conditions with toggling an ngAnimate on an element rapidly,
|
||||
* due to the asynchronous nature of addClass and removeClass
|
||||
*
|
||||
* Additionally, only toggle classes on requestAnimationFrame, to stop flickers on
|
||||
* iOS and older android for elements that were just attached to the DOM.
|
||||
*/
|
||||
angular.module('ionic')
|
||||
.factory('$animateClassToggler', [
|
||||
'$animate',
|
||||
'$rootScope',
|
||||
function($animate, $rootScope) {
|
||||
|
||||
return function(element, className) {
|
||||
|
||||
var self = {
|
||||
_nextOperation: null,
|
||||
_animating: false,
|
||||
_toggle: toggle,
|
||||
_animate: animate,
|
||||
_animationDone: animationDone,
|
||||
addClass: function() { self._toggle(true); },
|
||||
removeClass: function() { self._toggle(false); }
|
||||
};
|
||||
|
||||
return self;
|
||||
|
||||
function toggle(hasClass) {
|
||||
var operation = hasClass ? 'addClass' : 'removeClass';
|
||||
if (self._animating) {
|
||||
self._nextOperation = operation;
|
||||
} else {
|
||||
self._animate(operation);
|
||||
}
|
||||
}
|
||||
|
||||
function animate(operation) {
|
||||
self._animating = true;
|
||||
ionic.requestAnimationFrame(function() {
|
||||
$rootScope.$evalAsync(function() {
|
||||
$animate[operation](element, className, self._animationDone);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function animationDone() {
|
||||
self._animating = false;
|
||||
if (self._nextOperation) {
|
||||
self._animate(self._nextOperation);
|
||||
self._nextOperation = null;
|
||||
}
|
||||
}
|
||||
};
|
||||
}]);
|
||||
|
||||
17
js/ext/angular/src/service/ionicBackdrop.js
vendored
17
js/ext/angular/src/service/ionicBackdrop.js
vendored
@@ -4,14 +4,11 @@ angular.module('ionic')
|
||||
* @private
|
||||
*/
|
||||
.factory('$ionicBackdrop', [
|
||||
'$animate',
|
||||
'$document',
|
||||
'$animateClassToggler',
|
||||
function($animate, $document, $animateClassToggler) {
|
||||
function($document) {
|
||||
|
||||
var el = angular.element('<div class="backdrop ng-hide">');
|
||||
var el = angular.element('<div class="backdrop">');
|
||||
var backdropHolds = 0;
|
||||
var toggler = $animateClassToggler(el, 'ng-hide');
|
||||
|
||||
$document[0].body.appendChild(el[0]);
|
||||
|
||||
@@ -24,12 +21,18 @@ function($animate, $document, $animateClassToggler) {
|
||||
|
||||
function retain() {
|
||||
if ( (++backdropHolds) === 1 ) {
|
||||
toggler.removeClass();
|
||||
el.addClass('visible');
|
||||
ionic.requestAnimationFrame(function() {
|
||||
backdropHolds && el.addClass('active');
|
||||
});
|
||||
}
|
||||
}
|
||||
function release() {
|
||||
if ( (--backdropHolds) === 0 ) {
|
||||
toggler.addClass();
|
||||
el.removeClass('active');
|
||||
setTimeout(function() {
|
||||
!backdropHolds && el.removeClass('visible');
|
||||
}, 100);
|
||||
}
|
||||
}
|
||||
}]);
|
||||
|
||||
25
js/ext/angular/src/service/ionicLoading.js
vendored
25
js/ext/angular/src/service/ionicLoading.js
vendored
@@ -1,6 +1,6 @@
|
||||
|
||||
var TPL_LOADING =
|
||||
'<div class="loading ng-hide">' +
|
||||
'<div class="loading">' +
|
||||
'</div>';
|
||||
|
||||
var HIDE_LOADING_DEPRECATED = '$ionicLoading instance.hide() has been deprecated. Use $ionicLoading.hide().';
|
||||
@@ -33,7 +33,6 @@ angular.module('ionic.service.loading', [])
|
||||
* ```
|
||||
*/
|
||||
.factory('$ionicLoading', [
|
||||
'$animate',
|
||||
'$document',
|
||||
'$ionicTemplateLoader',
|
||||
'$ionicBackdrop',
|
||||
@@ -41,8 +40,7 @@ angular.module('ionic.service.loading', [])
|
||||
'$q',
|
||||
'$log',
|
||||
'$compile',
|
||||
'$animateClassToggler',
|
||||
function($animate, $document, $ionicTemplateLoader, $ionicBackdrop, $timeout, $q, $log, $compile, $animateClassToggler) {
|
||||
function($document, $ionicTemplateLoader, $ionicBackdrop, $timeout, $q, $log, $compile) {
|
||||
|
||||
var loaderInstance;
|
||||
//default value
|
||||
@@ -83,10 +81,9 @@ function($animate, $document, $ionicTemplateLoader, $ionicBackdrop, $timeout, $q
|
||||
})
|
||||
.then(function(loader) {
|
||||
|
||||
var toggler = $animateClassToggler(loader.element, 'ng-hide');
|
||||
var self = loader;
|
||||
|
||||
loader.show = function(options) {
|
||||
var self = this;
|
||||
var templatePromise = options.templateUrl ?
|
||||
$ionicTemplateLoader.load(options.templateUrl) :
|
||||
//options.content: deprecated
|
||||
@@ -114,10 +111,17 @@ function($animate, $document, $ionicTemplateLoader, $ionicBackdrop, $timeout, $q
|
||||
self.element.html(html);
|
||||
$compile(self.element.contents())(self.scope);
|
||||
}
|
||||
|
||||
//Don't show until template changes
|
||||
if (self.isShown) {
|
||||
self.element.addClass('visible');
|
||||
ionic.DomUtil.centerElementByMarginTwice(self.element[0]);
|
||||
ionic.requestAnimationFrame(function() {
|
||||
self.isShown && self.element.addClass('active');
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
toggler.removeClass();
|
||||
ionic.DomUtil.centerElementByMarginTwice(this.element[0]);
|
||||
this.isShown = true;
|
||||
};
|
||||
loader.hide = function() {
|
||||
@@ -125,7 +129,10 @@ function($animate, $document, $ionicTemplateLoader, $ionicBackdrop, $timeout, $q
|
||||
if (this.hasBackdrop) {
|
||||
$ionicBackdrop.release();
|
||||
}
|
||||
toggler.addClass();
|
||||
self.element.removeClass('active');
|
||||
setTimeout(function() {
|
||||
!self.isShown && self.element.removeClass('visible');
|
||||
}, 200);
|
||||
}
|
||||
$timeout.cancel(this.durationTimeout);
|
||||
this.isShown = false;
|
||||
|
||||
Reference in New Issue
Block a user