Skip to content

Commit

Permalink
Merge pull request #92 from alonl/master
Browse files Browse the repository at this point in the history
feat: Added a new param `insertBefore`
  • Loading branch information
ocombe committed Nov 11, 2014
2 parents ba02289 + e9b8572 commit c4f1038
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ $ocLazyLoad.load(
);
```

The existing parameters that you can use are `cache`, `reconfig`, `rerun` and `serie`.
The existing parameters that you can use are `cache`, `reconfig`, `rerun`, `serie` and `insertBefore`.
The parameter `cache: false` works for all native loaders (**all requests are cached by default**):

```js
Expand Down Expand Up @@ -185,6 +185,15 @@ $ocLazyLoad.load({
});
```

The files, by default, will be inserted before the last child of the `head` element. You can override this by using `insertBefore: 'cssSelector'`:
```js
$ocLazyLoad.load({
name: 'TestModule',
insertBefore: '#load_css_before',
files: ['bower_components/bootstrap/dist/css/bootstrap.css']
});
```

### Directive
The directive usage is very similar to the service. The main interest here is that the content will be included and compiled once your modules have been loaded.
This means that you can use directives that will be lazy loaded inside the oc-lazy-load directive.
Expand Down
10 changes: 9 additions & 1 deletion src/ocLazyLoad.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,15 @@
deferred.reject(new Error('Unable to load ' + path));
}
el.async = 1;
anchor.insertBefore(el, anchor.lastChild);

var insertBeforeElem = anchor.lastChild;
if(params.insertBefore) {
var element = angular.element(params.insertBefore);
if(element && element.length > 0) {
insertBeforeElem = element[0];
}
}
anchor.insertBefore(el, insertBeforeElem);

/*
The event load or readystatechange doesn't fire in:
Expand Down

0 comments on commit c4f1038

Please sign in to comment.