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

Responsive images lookup can be triggered at any time #23

Merged
merged 3 commits into from
Feb 8, 2016

Conversation

szwacz
Copy link
Contributor

@szwacz szwacz commented Feb 4, 2016

Fixes #14
You can do two things with this API:

  1. By calling
filepicker.responsive();

at any moment full lookup for images with data-fp-src will be performed.

  1. By passing as a parameter to this method DOM image element,
var img = document.querySelector('.my-img');
filepicker.responsive(img);

only this one image will be transformed to responsive.

Tested usage with masonry.js and unveil.js. Here are the samples: https://github.com/filepicker/filepicker-samples/tree/master/responsive_images

var responsiveImages = document.querySelectorAll('img[data-fp-src]');
for (var i = 0; i < responsiveImages.length; i++) {
construct(responsiveImages[i]);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why just don't call constructAll() here? It will do basically the same + it checks shouldConstruct(element).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw this when I pulled the repo, but I do not know the correct way to call it.... I made my own hack to make it work... but I would rather use the official release.

@szwacz
Copy link
Contributor Author

szwacz commented Feb 5, 2016

@krystiangw I need sometimes for construct to be forced, and shouldConstruct(element) doesn't allow me for that. But you're right I should reuse code here. done it more smart way now.

if (element.nodeName === 'IMG') {
construct(element);
} else {
throw new Error('Passed object is not an image');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use throw new fp.FilepickerException() here. Its simple filepicker libraryr wrapper for error object.

@szwacz
Copy link
Contributor Author

szwacz commented Feb 5, 2016

@krystiangw ok, done. Implementation of FilepickerException is far from perfect but for consistency reasons I'll use it.

@krystiangw
Copy link
Contributor

👍

krystiangw added a commit that referenced this pull request Feb 8, 2016
Responsive images lookup can be triggered at any time
@krystiangw krystiangw merged commit b1c2a04 into develop Feb 8, 2016
@tbono-pri
Copy link

Rock on!

@szwacz szwacz deleted the responsive-trigger branch August 17, 2016 12:13
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.

None yet

3 participants