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

Dynamically added images #93

Merged
merged 9 commits into from
May 11, 2016

Conversation

alexdrimbe
Copy link

No description provided.

@@ -171,6 +171,10 @@
return regex.test(element.href);
});
var gallery = [];

if(tagsNodeList.length === 0){
Copy link
Contributor

Choose a reason for hiding this comment

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

Spaces after if and before the bracket.

Copy link
Author

Choose a reason for hiding this comment

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

done

@alexdrimbe alexdrimbe force-pushed the dynamically-added-images-rebased branch 5 times, most recently from 388b6b4 to a92ac4e Compare April 4, 2016 08:44
unbind(imageElement, 'click', imagedEventHandlers[galleryID + '_' + imageElement]);
});
imagesMap.pop();
for(var selector in data) {
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 a space after keywords like if, for, etc.

Copy link
Author

Choose a reason for hiding this comment

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

done

@alexdrimbe alexdrimbe force-pushed the dynamically-added-images-rebased branch from a92ac4e to 1067976 Compare April 4, 2016 09:08
@XhmikosR
Copy link
Contributor

XhmikosR commented Apr 4, 2016

@alexdrimbe: make sure there are not new JSHint issues in your branch.

@alexdrimbe
Copy link
Author

There are no JSHint issues introduced by the new code.

@XhmikosR
Copy link
Contributor

@alexdrimbe: please fetch and rebase,

@alexdrimbe alexdrimbe changed the title Dynamically added images rebased Dynamically added images Apr 20, 2016
@alexdrimbe alexdrimbe force-pushed the dynamically-added-images-rebased branch from 1067976 to ad3cd01 Compare April 20, 2016 13:11
@@ -148,50 +146,75 @@
supports.svg = testSVGSupport();

buildOverlay();
destroyGalleriesForSelector(selector);
Copy link
Owner

Choose a reason for hiding this comment

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

Why do we destroy on run() ? I'm not sure I understand the function's responsibility.

Copy link
Author

Choose a reason for hiding this comment

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

When we call run() function multiple times for the same selector we want to destroy any cached data for selector and unbind its listeners.

@feimosi
Copy link
Owner

feimosi commented May 6, 2016

@alexdrimbe could you summarize this PR? I've already forgotten the essence of the change, besides significant code improvements (btw. great job!).

@alexdrimbe
Copy link
Author

@feimosi this PR could be summarize as follows: If you dynamically add or remove DOM elements from the gallery and then you call baguetteBox.run( someSelector ) again for the same selector the gallery works fine. Before, if you called 'run' function multiple times for the same selector, the click event was attached multiple times for the same elements and this is a source for memory leak; Now if you call run function multiple times it works properly.

Before:
before

With the change:
with the change

@alexdrimbe alexdrimbe force-pushed the dynamically-added-images-rebased branch from ad3cd01 to 9e5c800 Compare May 9, 2016 20:23
@alexdrimbe alexdrimbe force-pushed the dynamically-added-images-rebased branch from 9e5c800 to b2606ef Compare May 9, 2016 20:37
@alexdrimbe alexdrimbe force-pushed the dynamically-added-images-rebased branch from b2606ef to 4356ffd Compare May 9, 2016 20:55
@feimosi feimosi merged commit f23ef41 into feimosi:master May 11, 2016
@feimosi
Copy link
Owner

feimosi commented May 11, 2016

Ok, we're good to go with this PR. Really good job @alexdrimbe, thank you!
Also thanks @XhmikosR for reviewing the code on the way.

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