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

Fix/iframe attributes #269

Closed
wants to merge 6 commits into from
Closed

Conversation

nguyenj
Copy link
Contributor

@nguyenj nguyenj commented Dec 12, 2016

This PR addresses the issue that other data-featherlight-iframe-... attributes do not get added to the iframe when it's constructed because we're limited to just CSS attributes here.

@marcandre
Copy link
Collaborator

Looks like good work 👍

I added a few comments. Also, please don't change release, I will take care of that.

'sandbox', 'src', 'srcdoc', 'width'],
attrs = {};

whiteList.map(function(item) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why map? The return is unused...

};

function parseAttrs(obj, prefix) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use correct indent

@nguyenj
Copy link
Contributor Author

nguyenj commented Dec 12, 2016

@marcandre thanks for the review. I've updated the code with your comments.

@marcandre
Copy link
Collaborator

Forgot, but there should be a test modified or added that checks this too...

@nguyenj
Copy link
Contributor Author

nguyenj commented Dec 12, 2016

I added two tests, LMK.

Copy link
Collaborator

@marcandre marcandre left a comment

Choose a reason for hiding this comment

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

Good first test. Second one needs work

'data-featherlight-iframe-invalid="foo">').featherlight().click();

expect($('.featherlight iframe')).to.have.attr('src').equal('http://www.apple.com');
expect($('.featherlight iframe')).to.not.have.attr('allowfullscreen').equal('foo');
Copy link
Collaborator

Choose a reason for hiding this comment

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

Did you mean attr('invalid') instead of allowfullscreen? Otherwise the test makes no sense to me.
A shorter alternative would be to add this "not" test to the iframe css test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't add it to the CSS test because jQuery's .css should take care of invalid css attributes.

Copy link
Collaborator

@marcandre marcandre left a comment

Choose a reason for hiding this comment

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

If you really want to make things even nicer, it would be better to call parseAttrs once for both css and attributes, then split the result into attributes and css (would be nice but not necessary)

@@ -66,31 +66,31 @@
'sandbox', 'src', 'srcdoc', 'width'],
attrs = {};

whiteList.map(function(item) {
$.each(whiteList, function(index, item) {
var attrValue = parseAttrs(obj, 'iframe')[item];

if (attrValue) {
attrs[item] = attrValue;
return attrs[item];
Copy link
Collaborator

Choose a reason for hiding this comment

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

Useless return.

@@ -66,31 +66,31 @@
'sandbox', 'src', 'srcdoc', 'width'],
attrs = {};

whiteList.map(function(item) {
$.each(whiteList, function(index, item) {
var attrValue = parseAttrs(obj, 'iframe')[item];
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just noticed, but would be better to call parseAttrs once instead of once per item in whiteList...

@nguyenj
Copy link
Contributor Author

nguyenj commented Dec 12, 2016

I thought about doing that; but I wanted to leave the parseAttrs function generic in hopes for it to be reusable in other scenarios.

@marcandre
Copy link
Collaborator

You could leave parseAttrs as is and then split to result in two, no?

@marcandre
Copy link
Collaborator

marcandre commented Dec 12, 2016 via email

@nguyenj
Copy link
Contributor Author

nguyenj commented Dec 12, 2016

Ah, okay I understand. I'll add those a test for that.

@nguyenj
Copy link
Contributor Author

nguyenj commented Dec 12, 2016

I was thinking about refactoring readElementConfig to utilize parseAttrs; but I haven't gotten to chance to dive into it thoroughly yet; hence my hesitation on making it return an object with css or attr keys.

@marcandre
Copy link
Collaborator

marcandre commented Dec 12, 2016 via email

@marcandre
Copy link
Collaborator

Merged, refactored a bit. Good work, thanks!

Released in 1.7.0

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