Skip to content
This repository has been archived by the owner on Oct 1, 2023. It is now read-only.

Added IE8 support to script loading #26

Merged
merged 1 commit into from
Jan 12, 2016
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
2 changes: 1 addition & 1 deletion angular-load.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
var element = createElement(url);

element.onload = element.onreadystatechange = function (e) {
if (element.readyState && element.readyState !== 'complete') {
if (element.readyState && element.readyState !== 'complete' && element.readyState !== 'loaded') {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion angular-load.min.js

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

2 changes: 1 addition & 1 deletion angular-load.min.js.map

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

15 changes: 15 additions & 0 deletions tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,21 @@ describe('service angularLoad', function () {
expect(resolved).toBeTruthy();
});

it('should resolve the returned promise as soon as the script has finished loading when `onreadystatechange` callback is fired in IE8', function() {
var resolved = false;
angularLoad.loadScript('https://www.test.org/somescript.js').then(function() {
resolved = true;
});
var scriptElement = mockDocument.body.appendChild.calls.mostRecent().args[0];
scriptElement.readyState = 'loading';
scriptElement.onreadystatechange({});
expect(resolved).toBeFalsy();
scriptElement.readyState = 'loaded';
scriptElement.onreadystatechange({});
$timeout.flush();
expect(resolved).toBeTruthy();
});

it('should reject the returned promise if the script failed to load', function() {
var rejected = false;
angularLoad.loadScript('https://www.test.org/somescript.js').catch(function() {
Expand Down