-
-
Notifications
You must be signed in to change notification settings - Fork 677
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
Picture element not fetching correct source (Chrome, Firefox) #87
Comments
I think the fix is that we need to camelCase the data attribute before running it thru See https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset#Name_conversion I'll try and submit a pull request today or tomorrow. |
Thanks @toddmilliken, |
Ok no problem. I was thinking of adding a helper function to lazyload.setSources that will take a data attribute input and return the camelcase version. I'm able to get it working but am stuck on building the es6 minified version in the grunt uglify task. When I run |
Wait, what is the problem to be solved exactly? Why can't the final user already put the option in camel case instead of having the script to convert it? |
The issue is that the default attribute This is invalid because dataset accesses the attributes in camelcase form. It needs to be rewritten as: It looks like there is an option ( The pull request fixes the plugin out of the box by converting This article does a much better job of explaining than I can: Hope that makes sense. |
Thanks, |
If I understand correctly, you're asking if changing the default attributes in lazyload.defaults.js from: Is that correct? If that is the case, yes -- it would resolve partially but would have two side effects:
I'm not sure I can think of another way to solve this issue other than using the helper function to take whatever option is passed to |
Yes, |
Ok I think I understand. It seems a little odd that if a developer wants to override it, that they are forced to have an invalid HTML5 document using a camelcase data attribute on their source tags like It is possible this issue may come up for devs not intimate with the plugin; although it seems like an edge-case. Any specific reason why we shouldn't use the helper function? It will naturally fix all of the above scenarios without devs having to dig through the readME or being forced to have invalid HTML |
Hi @toddmilliken,
It isn't forced to do that. The HTML would still be: <picture>
<source data-my-data-src="...">
<img data-src="..."
</picture> And the js in that case would be: new LazyLoad({ data_srcset = "myDataSrc" }); That's because JS natively does the conversion of any "data-*" attribute to camelcase inside the element.dataset property. Check it out on this pen.
Because it would be replicating what the browser already does. :) |
PS: I'm trying the fix but I'm also having problems with uglify... :| |
Ah, ok i see what you mean. Devs just need to pass in their custom data attribute already in camelcase form for it to work; it's up to them to enter it in hyphenated lowercase form in their own HTML. Thanks for explaining that. Let me know if you want me to revise the pull request per your earlier instructions. Regarding uglify - I googled "online es6 minifier" and found this to minify lazyload.js to lazyload.min.js: Seems to work ok. |
I think the best thing is to create a new PR. |
@toddmilliken I'll create a PR myself, then we can discuss it together. |
Sorry @toddmilliken I was using a git-flow plugin which automatically pushed the fix on Github. |
This issue is related to with |
I have been a same problem, how I get version 7.2.2? I'm using npm but this version don't over there? For now I go back to version 7.1.0 how @Niresh12495 said above. |
On Chrome and Firefox, only the image on the
<img />
tag'sdata-original
attribute is loaded. The source element'sdata-original-set
attributes are ignored.I tested the demo and verified no change is occurring.
https://verlok.github.io/lazyload/demos/with_picture.html#/it/donna/stivaletti_cod44721746jj.html
I also put together a codepen and can verify its not change
https://codepen.io/emagine/pen/wdzyXq
I'm producing the issue on macOS 10.12.4 (Sierra) using Chrome 58 and Firefox 52.0.2.
Safari 10.1 is working, and Microsoft Edge seems to work when I loaded it up on browserstack.com
The text was updated successfully, but these errors were encountered: