-
Notifications
You must be signed in to change notification settings - Fork 216
fix(directive): check for existing elements before appending #167
base: master
Are you sure you want to change the base?
Conversation
Don't append elements that Masonry has already added to its items.
@@ -65,7 +65,10 @@ | |||
// Keep track of added elements. | |||
bricks[id] = true; | |||
defaultLoaded(element); | |||
$element.masonry(method, element, true); | |||
// Don't add element to Masonry if it already has it. | |||
if ($element.masonry('getItemElements').indexOf(element.get(0)) === -1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be O(n^2) when adding a list of n new elements, this seems like a very dangerous default. Is there any other way to address this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if there's a more "Angular" way of doing this, but within initialization of the masonry
directive, it could iterate once through every existing child element and run something like child.data('angularMasonryAdded', true)
. Then the above code could be changed to check if the element has that data
attribute, avoiding per-element iteration. What do you think?
…as static Using jQuery's data functionality, we can mark static elements upon initialization.
Avoid using possibly non-existent global $.
Angular-masonry supports dynamic elements by default; Be explicit in the specs that most cases involve dynamically repeating bricks
@passy Fixed the specs to reflect the general use of |
Don't append elements that Masonry has already added to its items.
This fixes the situation in which a static element has already been added to Masonry, but then the
masonry
directive attempts to add a newmasonry-brick
into Masonry's item list.