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

Add support for specifying parent container #86

Merged
merged 1 commit into from
Jun 21, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions nprogress.css
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@
animation: nprogress-spinner 400ms linear infinite;
}

.nprogress-custom-parent {
overflow: hidden;
position: relative;
}

.nprogress-custom-parent #nprogress .spinner,
.nprogress-custom-parent #nprogress .bar {
position: absolute;
}

@-webkit-keyframes nprogress-spinner {
0% { -webkit-transform: rotate(0deg); }
100% { -webkit-transform: rotate(360deg); }
Expand Down
9 changes: 8 additions & 1 deletion nprogress.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
showSpinner: true,
barSelector: '[role="bar"]',
spinnerSelector: '[role="spinner"]',
parent: 'body',
template: '<div class="bar" role="bar"><div class="peg"></div></div><div class="spinner" role="spinner"><div class="spinner-icon"></div></div>'
};

Expand Down Expand Up @@ -226,6 +227,7 @@

var bar = progress.querySelector(Settings.barSelector),
perc = fromStart ? '-100' : toBarPerc(NProgress.status || 0),
parent = document.querySelector(Settings.parent),
spinner;

css(bar, {
Expand All @@ -238,7 +240,11 @@
spinner && removeElement(spinner);
}

document.body.appendChild(progress);
if (parent != document.body) {
addClass(parent, 'nprogress-custom-parent');
}

parent.appendChild(progress);
return progress;
};

Expand All @@ -248,6 +254,7 @@

NProgress.remove = function() {
removeClass(document.documentElement, 'nprogress-busy');
removeClass(document.querySelector(Settings.parent), 'nprogress-custom-parent')
var progress = document.getElementById('nprogress');
progress && removeElement(progress);
};
Expand Down
12 changes: 8 additions & 4 deletions support/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ i, b {
font-weight: 400;
}

body, html {
padding: 0;
margin: 0;
}

body {
background: white;
}
Expand Down Expand Up @@ -130,11 +135,10 @@ button {
}

.page-header {
margin: 1.5em auto;
text-align: center;
max-width: 400px;
padding: 0 20px;
margin: 3em auto;
padding: 3em 20px;
margin: 0 auto;
}

.page-header h1 {
Expand Down Expand Up @@ -173,7 +177,7 @@ p.brief.big {
.page-header h1 {
font-size: 3em; }
.page-header {
margin: 4.5em auto 3.5em auto;
padding: 4.5em 20px 3.5em 20px;
}
}

Expand Down
21 changes: 21 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@
NProgress.start();
assert.equal(NProgress.status, NProgress.settings.minimum);
});

it('must be attached to specified parent', function() {
var test = $('<div>', {id: 'test'}).appendTo('body');
NProgress.configure({parent: '#test'});
NProgress.start();
assert.isTrue($("#nprogress").parent().is(test));
assert.isTrue($(NProgress.settings.parent).hasClass("nprogress-custom-parent"));
});
});

// ----
Expand All @@ -91,6 +99,19 @@

// ----

describe('.remove()', function() {
it('should be removed from the parent', function() {
NProgress.set(1);
NProgress.remove();

var parent = $(NProgress.settings.parent);
assert.isFalse(parent.hasClass('nprogress-custom-parent'));
assert.equal(parent.find('#nprogress').length, 0);
});
})

// ----

describe('.inc()', function() {
it('should render', function() {
NProgress.inc();
Expand Down