Skip to content
This repository has been archived by the owner on Jun 18, 2022. It is now read-only.

Conflict with flickity #49

Closed
JoshMoreno opened this issue Nov 25, 2016 · 6 comments
Closed

Conflict with flickity #49

JoshMoreno opened this issue Nov 25, 2016 · 6 comments

Comments

@JoshMoreno
Copy link

I'm using flickity in my project and it breaks this polyfill for ie edge 14. Didn't test in anything else, but I'm sure it's the same story.

No console errors. Just breaks it silently.

Not sure if I should be posting here or over on flickity's issues. Sorry if I'm posting in the wrong place.

I was trying to read the code for this polyfill, but I don't see an unminified version here and can't wrap my head around the minified code. And for figuring out flickity...it's like 4,000 lines long so would rather just try and tweak the smaller script if possible.

Any ideas on how to possible get it working?

Thanks

@fregante
Copy link
Owner

fregante commented Nov 25, 2016

This is the source: https://github.com/bfred-it/object-fit-images/blob/master/index.js

What's broken exactly? OFI doesn't run at all and therefore object-fit isn't polyfilled, or the images disappear?

It's hard to find the issue without seeing your page/site

@JoshMoreno
Copy link
Author

JoshMoreno commented Nov 25, 2016 via email

@fregante
Copy link
Owner

If it doesn't seem to run at all, either flickity is moving the images around or you're not waiting for the document to be ready. What's your initialization code? objectFitImages();?

@JoshMoreno
Copy link
Author

Thanks for your help @bfred-it , got it sorted out. Not a conflict. It seems that the DOM wasn't ready. I was using

document.addEventListener('DOMContentLoaded', function () {
    objectFitImages();
});

I added jQuery and used this instead and everything works as expected.

$(function(){
    objectFitImages();
});

I'll post back if I find a reliable way to get it working with vanilla JS. Unless you have any ideas?

Thanks again! Super helpful.

@JoshMoreno
Copy link
Author

So it was because I was using async that I was missing the DOMContentLoaded event. Using this helper function from http://youmightnotneedjquery.com/

function ready(fn) {
  if (document.readyState != 'loading'){
    fn();
  } else {
    document.addEventListener('DOMContentLoaded', fn);
  }
}

// and usage like so
ready(function(){
    objectFitImages();
});

Everything seems to be working as it should. Thanks again. Sorry my fault.

@fregante
Copy link
Owner

fregante commented Nov 26, 2016

Glad you got it sorted out, thanks for sharing your solution!

fregante pushed a commit that referenced this issue Jan 7, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants