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

Added 'cssFilesInsertBefore' parameter #92

Merged
merged 1 commit into from
Nov 11, 2014
Merged

Conversation

alonl
Copy link

@alonl alonl commented Nov 11, 2014

Added an option to provide 'cssFilesInsertBefore', for inserting css files before a specific element.
#91

@ocombe
Copy link
Owner

ocombe commented Nov 11, 2014

Don't define cssFilesInsertBefore as a global config option, use the params instead so that it can be defined as a "when you need it". Params can be defined in a module config object like this:

$ocLazyLoad.load({
    name: 'mgcrea.ngStrap',
    insertBefore: "#myId",
    files: [
        'bower_components/angular-strap/dist/angular-strap.js',
        'bower_components/angular-strap/dist/angular-strap.tpl.js'
    ]
});

or as an option config object (defined for all modules lazy loaded with this function when used as the second parameter):

$ocLazyLoad.load(
  [{ name: 'mgcrea.ngStrap', files: [ ... ] }, { .... }],
  { insertBefore: "div .myClass" }
);

It would take a css selector. If you define a css selector that returns multiple elements, it will only take the first one into account (use querySelectorAll).

Maybe that you could define multiple choices, like insertBefore, insertAfter, appendTo. It should affect cssLoader & jsLoader if you use it in the buildElement function (not sure if it would really be of any use for the jsLoader function though).

@ocombe
Copy link
Owner

ocombe commented Nov 11, 2014

Also you should edit the README.md to add this new param and explain how it works. Add a note about browser support of querySelectorAll (in IE8 it only works with css2 selectors)

@alonl
Copy link
Author

alonl commented Nov 11, 2014

Done. Hope that's fine.

@ocombe
Copy link
Owner

ocombe commented Nov 11, 2014

Almost, just change:

var insertBeforeElem = angular.element(params.insertBefore) || anchor.lastChild;

to

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

We don't want to do a DOM query every time for nothing (moreover when you know that this param will rarely be used).
I'll you test it to make sure that it works :)

@alonl
Copy link
Author

alonl commented Nov 11, 2014

Got it. I've tested it of course. :)

ocombe added a commit that referenced this pull request Nov 11, 2014
feat: Added a new param `insertBefore`
@ocombe ocombe merged commit c4f1038 into ocombe:master Nov 11, 2014
@ocombe
Copy link
Owner

ocombe commented Nov 11, 2014

Thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants