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

feat($anchorScroll): allow scrolling to a specified element #9596

Closed
wants to merge 1 commit into from

Conversation

@gkalpak
Copy link
Member

@gkalpak gkalpak commented Oct 13, 2014

Add an optional argument to $anchorScroll() to enable scrolling to an anchor element different than that related to the current value of $location.hash(). If the argument is omitted, the value of $location.hash() will be used instead.

Closes #4568

@tbosch tbosch self-assigned this Oct 13, 2014
@tbosch tbosch modified the milestones: low, Backlog Oct 13, 2014
@tbosch tbosch removed their assignment Oct 13, 2014
@gkalpak gkalpak force-pushed the gkalpak:$anchorScroll-explicit-hash branch 4 times, most recently from 671bf6b to b691f39 Oct 14, 2014
@petebacondarwin petebacondarwin force-pushed the angular:master branch from 4dd5a20 to 998c61c Oct 19, 2014
@gkalpak gkalpak force-pushed the gkalpak:$anchorScroll-explicit-hash branch 7 times, most recently from b4f3d67 to b00921b Oct 20, 2014
@gkalpak gkalpak force-pushed the gkalpak:$anchorScroll-explicit-hash branch 5 times, most recently from d915061 to dda4c91 Oct 28, 2014
@gkalpak gkalpak force-pushed the gkalpak:$anchorScroll-explicit-hash branch from dda4c91 to 6b6fef7 Nov 10, 2014
@gkalpak
Copy link
Member Author

@gkalpak gkalpak commented Nov 10, 2014

Small and safe little feature, with docs and tests - what's not to love about this PR (even Travis likes it) ;)

@gkalpak gkalpak force-pushed the gkalpak:$anchorScroll-explicit-hash branch from 6b99562 to 14c5216 Nov 23, 2014
@googlebot
Copy link

@googlebot googlebot commented Nov 23, 2014

CLAs look good, thanks!

@gkalpak gkalpak force-pushed the gkalpak:$anchorScroll-explicit-hash branch 3 times, most recently from f9fa6dc to ef451f7 Nov 24, 2014
@gkalpak gkalpak force-pushed the gkalpak:$anchorScroll-explicit-hash branch 2 times, most recently from dacfd0a to ab050c4 Dec 7, 2014
@gkalpak gkalpak force-pushed the gkalpak:$anchorScroll-explicit-hash branch from ab050c4 to 2068e44 Dec 19, 2014
@gkalpak gkalpak force-pushed the gkalpak:$anchorScroll-explicit-hash branch from 2068e44 to ecba1e5 Jan 20, 2015
@gkalpak gkalpak force-pushed the gkalpak:$anchorScroll-explicit-hash branch from ecba1e5 to 04cd27f Feb 19, 2015
@gkalpak gkalpak force-pushed the gkalpak:$anchorScroll-explicit-hash branch from 04cd27f to 6b2549d Mar 27, 2015
return function($anchorScroll) {
$anchorScroll();
$anchorScroll.apply(null, args);

This comment has been minimized.

@petebacondarwin

petebacondarwin Apr 2, 2015
Member

Why does this need to be so complicated? Could it not simply be:

function callAnchorScroll(hash) {
  return function($anchorScroll) {
    $anchorScroll(hash);
  };
}

This comment has been minimized.

@gkalpak

gkalpak Apr 2, 2015
Author Member

Hm...why indeed ?

function scroll() {
var hash = $location.hash(), elm;
function scroll(hash) {
hash = (arguments.length && isString(hash)) ? hash : $location.hash();

This comment has been minimized.

@petebacondarwin

petebacondarwin Apr 2, 2015
Member

Can we not just check whether hash is undefined?

This comment has been minimized.

@gkalpak

gkalpak Apr 2, 2015
Author Member

That would be the reasonable thing to do :)
I was trying to avoid accidentally breaking an existing app, by ensuring that the hash argument is a string.
It's been a while, so I am not really sure about the arguments.length check; I suspect it was me micro-optimizing (or at least believing so).

It seems that isString(hash) ? hash : $location.hash() would be enough.

I would rather use isString() instead of isDefined(), to avoid breaking some unlikely construct like:

elem.on('click', $anchorScroll);   // e.g. passing and event object will be ignored
@petebacondarwin
Copy link
Member

@petebacondarwin petebacondarwin commented Apr 2, 2015

I would make the commit title: feat($anchorScroll): allow scrolling to a specified element

@petebacondarwin
Copy link
Member

@petebacondarwin petebacondarwin commented Apr 2, 2015

If you could deal with the small comments above then LGTM

@gkalpak gkalpak force-pushed the gkalpak:$anchorScroll-explicit-hash branch 3 times, most recently from 3b9232a to d741c09 Apr 2, 2015
@gkalpak gkalpak changed the title feat($anchorScroll): add support for scrolling independently of $location.hash() feat($anchorScroll): allow scrolling to a specified element Apr 2, 2015
@petebacondarwin
Copy link
Member

@petebacondarwin petebacondarwin commented Apr 2, 2015

LGTM

Add an optional argument to `$anchorScroll()` to enable scrolling to an
anchor element different than that related to the current value of
`$location.hash()`. If the argument is omitted or is not a string,
the value of `$location.hash()` will be used instead.

Closes #4568
@gkalpak gkalpak force-pushed the gkalpak:$anchorScroll-explicit-hash branch from d741c09 to 55f44b7 Apr 2, 2015
@gkalpak gkalpak closed this in 731c8b5 Apr 2, 2015
@gkalpak gkalpak deleted the gkalpak:$anchorScroll-explicit-hash branch Apr 2, 2015
netman92 added a commit to netman92/angular.js that referenced this pull request Aug 8, 2015
Add an optional argument to `$anchorScroll()` to enable scrolling to an
anchor element different than that related to the current value of
`$location.hash()`. If the argument is omitted or is not a string,
the value of `$location.hash()` will be used instead.

Closes angular#4568
Closes angular#9596
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

5 participants