Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XOR switching between bar and spinner #367

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/loading-bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ angular.module('cfp.loadingBarInterceptor', ['cfp.loadingBar'])
$rootScope.$broadcast('cfpLoadingBar:loading', {url: config.url});
if (reqsTotal === 0) {
startTimeout = $timeout(function() {
cfpLoadingBar.start();
cfpLoadingBar.start(config.switchMethods);
}, latencyThreshold);
}
reqsTotal++;
Expand Down Expand Up @@ -168,6 +168,7 @@ angular.module('cfp.loadingBar', [])
this.parentSelector = 'body';
this.spinnerTemplate = '<div id="loading-bar-spinner"><div class="spinner-icon"></div></div>';
this.loadingBarTemplate = '<div id="loading-bar"><div class="bar"><div class="peg"></div></div></div>';
this.switchMethods = false;

this.$get = ['$injector', '$document', '$timeout', '$rootScope', function ($injector, $document, $timeout, $rootScope) {
var $animate;
Expand All @@ -185,11 +186,12 @@ angular.module('cfp.loadingBar', [])
var includeSpinner = this.includeSpinner;
var includeBar = this.includeBar;
var startSize = this.startSize;
var switchMethods = this.switchMethods;

/**
* Inserts the loading bar element into the dom, and sets it to 2%
*/
function _start() {
function _start(switchMethods) {
if (!$animate) {
$animate = $injector.get('$animate');
}
Expand Down Expand Up @@ -217,11 +219,13 @@ angular.module('cfp.loadingBar', [])
$rootScope.$broadcast('cfpLoadingBar:started');
started = true;

if (includeBar) {
//XOR with switchMethods

if ((includeBar && !switchMethods) || (!includeBar && switchMethods)) {
$animate.enter(loadingBarContainer, $parent, $after);
}

if (includeSpinner) {
if ((includeSpinner && !switchMethods) || (!includeSpinner && switchMethods)) {
$animate.enter(spinner, $parent, loadingBarContainer);
}

Expand Down