Skip to content

Commit

Permalink
fix(loading): make showDelay option work correctly
Browse files Browse the repository at this point in the history
The 'showDelay' configuration option of $ionicLoading exists but
does not lead to any delay whatsoever.

This change implements that functionality.

Closes #562
  • Loading branch information
maitai authored and ajoslin committed Feb 17, 2014
1 parent 70d9524 commit 7281e2a
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions js/views/loadingView.js
@@ -1,10 +1,10 @@
(function(ionic) {
'use strict';
/**
* An ActionSheet is the slide up menu popularized on iOS.
* Loading
*
* You see it all over iOS apps, where it offers a set of options
* triggered after an action.
* The Loading is an overlay that can be used to indicate
* activity while blocking user interaction.
*/
ionic.views.Loading = ionic.views.View.inherit({
initialize: function(opts) {
Expand All @@ -14,6 +14,8 @@

this.maxWidth = opts.maxWidth || 200;

this.showDelay = opts.showDelay || 0;

this._loadingBox = this.el.querySelector('.loading');
},
show: function() {
Expand All @@ -29,13 +31,19 @@
lb.style.marginLeft = (-lb.offsetWidth) / 2 + 'px';
lb.style.marginTop = (-lb.offsetHeight) / 2 + 'px';

_this.el.classList.add('active');
// Wait 'showDelay' ms before showing the loading screen
this._showDelayTimeout = window.setTimeout(function() {
_this.el.classList.add('active');
}, _this.showDelay);
}
},
hide: function() {
// Force a reflow so the animation will actually run
this.el.offsetWidth;

// Prevent unnecessary 'show' after 'hide' has already been called
window.clearTimeout(this._showDelayTimeout);

this.el.classList.remove('active');
}
});
Expand Down

0 comments on commit 7281e2a

Please sign in to comment.