-
Notifications
You must be signed in to change notification settings - Fork 27.4k
ANCHOR SCROLL: chore(docs): add directive to pad heading anchors #9368
Conversation
@IgorMinar and @gkalpak - can you consider this solution? |
A complete solution (for Angular.js) will require some changes to the dgeni-packages/ngdoc templates since there are situations where we are using |
Here is an example of it working: https://ci.angularjs.org/job/angular.js-pete/678/artifact/build/docs/guide/compiler#understanding-view It doesn't yet work for the link given in the issue: https://docs.angularjs.org/api/ng/service/%24animate#removeClass since this is one of those where the id is on an |
/** | ||
* @ngdoc service | ||
* @description | ||
* The offset to use for heading anchors if not specific offset is given using ngOffSet. |
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.
ngOffset
(with lowercase s
).
}; | ||
|
||
// Work out whether we are using a specific offset or getting the global default | ||
if ( attrs.ngOffset ) { |
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 is a detail, but theoretically we should check if the ng-offset
property exists, because we might have an initially falsy value (in order to use the default headingOffset.value
), but later on (based on some event) assign a proper value to ngOffset
.
E.g.
<h1 id="heading1" ng-offset={{(someCondition) ? '120px' : ''}}></h1>
will end up using headingOffset.value
forever (even after someCondition
evaluates to true).
Additionally, it might be a good idea to add a check in updateStyle()
:
var updateStyle = function (offset) {
offset = offset || headingOffset.value;
if (offset) {
...
}
};
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.
My view was that if the ngOffset attribute is ever defined then it should never default to the global headingOffset value. Is that wrong do you think?
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.
The idea is to support having ngOffset evaluate to something under some condition, or evaluate to undefined or null if the condition is not met and let the default headingOffset be used.
E.g. having the following HTML:
<h1 id="heading1" ng-offset="{{weAreOnSmallScreen() ? '0px' : ''}}">Heading 1</h1>
we could account for the following scenario (based on how the docs app is designed):
if we are on a small screen, the header's positioning becomes static (not fixed), so we don't need an offset. So, if weAreOnSmallScreen()
evaluates to true, use the value of ngOffset (which is '0px'
).
If we are on a large screen, the header is fixed and we should use the default offset of headingOffset.value
. weAreOnSmallScreen()
evaluates to true, attrs.ngOffset
evaluates to ''
(empty string) and the updateStyle()
function understands that it should use the default offset.
This is indeed an implementation choice (i.e. nothing inherenty wrong if we don't support it) and the added flexibility might not be worth the trouble. Up to you :)
Other than my comments above, it LTGM ! |
Hm... @petebacondarwin, I just took a look at |
@gkalpak - excellent review. Thanks for that. I'll fix up the PR. |
Add support for a configurable scroll offset to $anchorScrollProvider. The offset is expressed in pixels and can be specified either as a fixed value or as a function that return the offset it pixels dynamically. (This is a POC and a WIP: no docs, no tests) Related to angular#9368 Closes angular#2070, angular#9360
@gkalpak - I see you have created your own PR. I will take a look. In the meantime I have updated mine with fixes. |
* }]); | ||
* ``` | ||
* | ||
* Be aware that this moves the id to a span below the original element which can play havoc with you |
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.
...with your...
Add support for a configurable scroll offset to $anchorScrollProvider. The offset is expressed in pixels and can be specified either as a fixed value or as a function that return the offset it pixels dynamically. (This is a POC and a WIP: no docs, no tests) Related to angular#9368 Closes angular#2070, angular#9360
Closing in favour of #9371 |
Add support for a configurable scroll offset to $anchorScrollProvider. Related to angular#9368 Closes angular#2070 Closes angular#9371
Add support for a configurable vertical scroll offset to `$anchorScroll`. The offset can be defined by a specific number of pixels, a callback function that returns the number of pixels on demand or a jqLite/JQuery wrapped DOM element whose height and position are used if it has fixed position. The offset algorithm takes into account items that are near the bottom of the page preventing over-zealous offset correction. Closes angular#9368 Closes angular#2070 Closes angular#9360
Add support for a configurable scroll offset to $anchorScrollProvider. The offset is expressed in pixels and can be specified either as a fixed value or as a function that return the offset it pixels dynamically. (This is a POC and a WIP: no docs, no tests) Related to angular#9368 Closes angular#2070, angular#9360
Add support for a configurable vertical scroll offset to `$anchorScroll`. The offset can be defined by a specific number of pixels, a callback function that returns the number of pixels on demand or a jqLite/JQuery wrapped DOM element whose height and position are used if it has fixed position. The offset algorithm takes into account items that are near the bottom of the page preventing over-zealous offset correction. Closes angular#9368 Closes angular#2070 Closes angular#9360
Add support for a configurable scroll offset to $anchorScrollProvider. The offset is expressed in pixels and can be specified either as a fixed value or as a function that return the offset it pixels dynamically. (This is a POC and a WIP: no docs, no tests) Related to angular#9368 Closes angular#2070, angular#9360
Add support for a configurable vertical scroll offset to `$anchorScroll`. The offset can be defined by a specific number of pixels, a callback function that returns the number of pixels on demand or a jqLite/JQuery wrapped DOM element whose height and position are used if it has fixed position. The offset algorithm takes into account items that are near the bottom of the page preventing over-zealous offset correction. Closes angular#9368 Closes angular#2070 Closes angular#9360
Add support for a configurable vertical scroll offset to `$anchorScroll`. The offset can be defined by a specific number of pixels, a callback function that returns the number of pixels on demand or a jqLite/JQuery wrapped DOM element whose height and position are used if it has fixed position. The offset algorithm takes into account items that are near the bottom of the page preventing over-zealous offset correction. Closes angular#9368 Closes angular#2070 Closes angular#9360
Add support for a configurable vertical scroll offset to `$anchorScroll`. The offset can be defined by a specific number of pixels, a callback function that returns the number of pixels on demand or a jqLite/JQuery wrapped DOM element whose height and position are used if it has fixed position. The offset algorithm takes into account items that are near the bottom of the page preventing over-zealous offset correction. Closes angular#9368 Closes angular#2070 Closes angular#9360
Add support for a configurable vertical scroll offset to `$anchorScroll`. The offset can be defined by a specific number of pixels, a callback function that returns the number of pixels on demand or a jqLite/JQuery wrapped DOM element whose height and position are used if it has fixed position. The offset algorithm takes into account items that are near the bottom of the page preventing over-zealous offset correction. Closes angular#9368 Closes angular#2070 Closes angular#9360
Add support for a configurable vertical scroll offset to `$anchorScroll`. The offset can be defined by a specific number of pixels, a callback function that returns the number of pixels on demand or a jqLite/JQuery wrapped DOM element whose height and position are used if it has fixed position. The offset algorithm takes into account items that are near the bottom of the page preventing over-zealous offset correction. Closes angular#9368 Closes angular#2070 Closes angular#9360
Add support for a configurable vertical scroll offset to `$anchorScroll`. The offset can be defined by a specific number of pixels, a callback function that returns the number of pixels on demand or a jqLite/JQuery wrapped DOM element whose height and position are used if it has fixed position. The offset algorithm takes into account items that are near the bottom of the page preventing over-zealous offset correction. Closes angular#9368 Closes angular#2070 Closes angular#9360
Add support for a configurable vertical scroll offset to `$anchorScroll`. The offset can be defined by a specific number of pixels, a callback function that returns the number of pixels on demand or a jqLite/JQuery wrapped DOM element whose height and position are used if it has fixed position. The offset algorithm takes into account items that are near the bottom of the page preventing over-zealous offset correction. Closes angular#9368 Closes angular#2070 Closes angular#9360
Add support for a configurable vertical scroll offset to `$anchorScroll`. The offset can be defined by a specific number of pixels, a callback function that returns the number of pixels on demand or a jqLite/JQuery wrapped DOM element whose height and position are used if it has fixed position. The offset algorithm takes into account items that are near the bottom of the page preventing over-zealous offset correction. Closes angular#9368 Closes angular#2070 Closes angular#9360
Closes #2070
Closes #9360