Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

fix($animate): insert elements at the start of the parent container instead of at the end #6663

Closed
wants to merge 1 commit into from

Conversation

matsko
Copy link
Contributor

@matsko matsko commented Mar 12, 2014

With 1.2.x, $animate.enter and $animate.move both insert the element at the end of the provided
parent container element when only the parent element is provided. If an after element is provided
then they will place the inserted element after that one. This works fine, but there is no way to
place an item at the top of the provided parent container using these two APIs.

With this change, if the after argument is not specified for either $animate.enter or $animate.move,
the new child element will be inserted into the first position of the parent container element.

Closes #4934
Closes #6275

BREAKING CHANGE: $animate will no longer default the after parameter to the last element of the parent
container. Instead, when after is not specified, the new element will be inserted as the first child of
the parent container.

To update existing code, change all instances of $animate.enter() or $animate.move() from:

$animate.enter(element, parent);

to:

$animate.enter(element, parent, angular.element(parent[0].lastChild));

@mary-poppins
Copy link

Matias!

@@ -128,7 +128,7 @@ var $AnimateProvider = ['$provide', function($provide) {
if (!parent || !parent[0]) {
parent = after.parent();
Copy link

Choose a reason for hiding this comment

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

semi unrelated, but does this actually work?

if (after) {
   ...
} else {
  ...
  parent = after.parent();

looks to me like after could never exist when you are here?

I think it might be left over from when this was using the native js insert fuction.

also there is a comment there that might need to be updated from append to prepend

 * @param {DOMElement} parent the parent element which will append the element as
 *   a child (if the after element is not present)

Copy link
Contributor

Choose a reason for hiding this comment

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

semi unrelated, but does this actually work?

No, an issue has been raised about this before, currently $animate.enter() will throw if either the parent or after are not supplied. That entire branch should probably be removed, or at least clarified to explain that failure is due to both parent and after being undefined.

Copy link
Contributor

Choose a reason for hiding this comment

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

Are you refering to this issue? #6275

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've refactored enter. I don't think we need any special error to be thrown if both parent + after are missing since there could be a deeper error incase an empty jqLite/jQuery object wrapper is provided anyway, or if a comment node is in place.

@Narretz
Copy link
Contributor

Narretz commented Mar 13, 2014

Also closes #6274

@btford btford added this to the 1.3.0-beta.3 milestone Mar 17, 2014
@matsko matsko added cla: yes and removed cla: no labels Mar 18, 2014
@btford btford modified the milestones: 1.3.0-beta.4, 1.3.0-beta.3 Mar 24, 2014
element.append(jqLite('<div> ' + i + '</div>'));
}

var child = $compile('<div>first</div>')($rootScope);
Copy link
Contributor

Choose a reason for hiding this comment

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

what's the purpose of compilation here? it seems unnecessary.

@IgorMinar
Copy link
Contributor

no matter what, this PR needs better commit message explaining what this actually means for the developer and possibly even a note in api docs.

@IgorMinar
Copy link
Contributor

the commit message has not been updated as I request ;-)

@IgorMinar
Copy link
Contributor

imagine that you are a developer that knows only very little about $animate, the commit message makes it hard for me to understand what to do.

can you make the text more clear and add an example like:

give existing animation code like:

$animate.enter(.....);

you'll need to change it to:

$animate.enter(....);

@njs50
Copy link

njs50 commented Apr 1, 2014

perhaps it could be worded something like:

BREAKING CHANGE: $animate will no longer default the after parameter to the last element of the parent container. When after is not specified the new element will be inserted before the first element of the parent container. To update existing code change any instances of $animate.enter() or $animate.move() from:

$animate.enter(element, parent);

to

$animate.enter(element, parent, angular.element(parent[0].lastChild));

…nstead of at the end

With 1.2.x, $animate.enter and $animate.move both insert the element at the end of the provided
parent container element when only the parent element is provided. If an after element is provided
then they will place the inserted element after that one. This works fine, but there is no way to
place an item at the top of the provided parent container using both these functions.

Closes angular#4934
Closes angular#6275

BREAKING CHANGE: $animate will no longer default the after parameter to the last element of the parent
container. Instead, when after is not specified, the new element will be inserted as the first child of
the parent container.

To update existing code change any instances of $animate.enter() or $animate.move() from:

`$animate.enter(element, parent);`

to:

`$animate.enter(element, parent, angular.element(parent[0].lastChild));`
@matsko
Copy link
Contributor Author

matsko commented Apr 3, 2014

MERGED

@matsko
Copy link
Contributor Author

matsko commented Apr 3, 2014

Landed as 1cb8584

@matsko matsko closed this Apr 3, 2014
@matsko matsko deleted the animate_final branch April 3, 2014 21:09
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.