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 #33

Closed
wants to merge 1 commit into from
Closed
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
14 changes: 12 additions & 2 deletions nprogress.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#nprogress .bar {
background: #29d;

position: fixed;
position: absolute;
z-index: 100;
top: 0;
left: 0;
Expand All @@ -33,7 +33,7 @@
/* Remove these to get rid of the spinner */
#nprogress .spinner {
display: block;
position: fixed;
position: absolute;
z-index: 100;
top: 15px;
right: 15px;
Expand All @@ -53,6 +53,16 @@
animation: nprogress-spinner 400ms linear infinite;
}

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

body.nprogress-parent #nprogress .bar,
body.nprogress-parent #nprogress .spinner {
position: fixed;
}

@-webkit-keyframes nprogress-spinner {
0% { -webkit-transform: rotate(0deg); }
100% { -webkit-transform: rotate(360deg); }
Expand Down
6 changes: 5 additions & 1 deletion nprogress.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
trickleRate: 0.02,
trickleSpeed: 800,
showSpinner: true,
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 @@ -185,7 +186,9 @@
if (!Settings.showSpinner)
$el.find('[role="spinner"]').remove();

$el.appendTo(document.body);
$(Settings.parent)
.addClass('nprogress-parent')
.append($el);

return $el;
};
Expand All @@ -195,6 +198,7 @@
*/

NProgress.remove = function() {
$(Settings.parent).removeClass('nprogress-parent');
$('html').removeClass('nprogress-busy');
$('#nprogress').remove();
};
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-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-parent'));
assert.equal(parent.find('#nprogress').length, 0);
});
})

// ----

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