Skip to content

Allow empty parentSelector. #218

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

Closed
wants to merge 3 commits 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
test/coverage
bower_components
.idea
8 changes: 5 additions & 3 deletions build/loading-bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,9 @@ angular.module('cfp.loadingBar', [])
$animate = $injector.get('$animate');
}

var $parent = $document.find($parentSelector).eq(0);
// $document.find is limited to lookups by tag name in jqLite
// https://docs.angularjs.org/api/ng/function/angular.element
var $parent = angular.element($document[0].querySelector($parentSelector)).eq(0);
$timeout.cancel(completeTimeout);

// do not continually broadcast the started event:
Expand All @@ -212,11 +214,11 @@ angular.module('cfp.loadingBar', [])
started = true;

if (includeBar) {
$animate.enter(loadingBarContainer, $parent, angular.element($parent[0].lastChild));
$animate.enter(loadingBarContainer, $parent, $parent[0].lastChild && angular.element($parent[0].lastChild));
}

if (includeSpinner) {
$animate.enter(spinner, $parent, angular.element($parent[0].lastChild));
$animate.enter(spinner, $parent, $parent[0].lastChild && angular.element($parent[0].lastChild));
}

_set(startSize);
Expand Down
2 changes: 1 addition & 1 deletion build/loading-bar.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions src/loading-bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ angular.module('cfp.loadingBar', [])
$animate = $injector.get('$animate');
}

var $parent = $document.find($parentSelector).eq(0);
// $document.find is limited to lookups by tag name in jqLite
// https://docs.angularjs.org/api/ng/function/angular.element
var $parent = angular.element($document[0].querySelector($parentSelector)).eq(0);
$timeout.cancel(completeTimeout);

// do not continually broadcast the started event:
Expand All @@ -206,11 +208,11 @@ angular.module('cfp.loadingBar', [])
started = true;

if (includeBar) {
$animate.enter(loadingBarContainer, $parent, angular.element($parent[0].lastChild));
$animate.enter(loadingBarContainer, $parent, $parent[0].lastChild && angular.element($parent[0].lastChild));
}

if (includeSpinner) {
$animate.enter(spinner, $parent, angular.element($parent[0].lastChild));
$animate.enter(spinner, $parent, $parent[0].lastChild && angular.element($parent[0].lastChild));
}

_set(startSize);
Expand Down
17 changes: 17 additions & 0 deletions test/loading-bar-interceptor-config.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,20 @@ describe 'loadingBarInterceptor Service - config options', ->
expect(cfpLoadingBar.status()).toBeGreaterThan .5
cfpLoadingBar.complete()
$timeout.flush()

it 'should append the loadingbar as the first child of the parent container if empty', ->
emptyEl = angular.element '<div id="empty"></div>'
angular.element(document).find('body').eq(0).append emptyEl

module 'chieffancypants.loadingBar', (cfpLoadingBarProvider) ->
cfpLoadingBarProvider.parentSelector = '#empty'
return
inject ($timeout, $document, cfpLoadingBar) ->
cfpLoadingBar.start()
parent = $document[0].querySelector(cfpLoadingBar.parentSelector)
children = parent.childNodes
expect(children.length).toBe 2
expect(children[0].id).toBe 'loading-bar'
expect(children[1].id).toBe 'loading-bar-spinner'
cfpLoadingBar.complete()
$timeout.flush()