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

Commit 9ef217e

Browse files
style($anchorScroll): minor docs and test tweaks (to be squashed)
1 parent 2c995eb commit 9ef217e

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

src/ng/anchorScroll.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* @description
88
* Use `$anchorScrollProvider` to disable automatic scrolling whenever
9-
* {@link ng.$location#hash $location.hash()} changes.
9+
* {@link ng.$location#hash `$location.hash()`} changes.
1010
*/
1111
function $AnchorScrollProvider() {
1212

@@ -17,12 +17,12 @@ function $AnchorScrollProvider() {
1717
* @name $anchorScrollProvider#disableAutoScrolling
1818
*
1919
* @description
20-
* By default, {@link ng.$anchorScroll $anchorScroll()} will automatically will detect changes to
21-
* {@link ng.$location#hash $location.hash()} and scroll to the element matching the new hash.<br />
20+
* By default, {@link $anchorScroll `$anchorScroll()`} will automatically will detect changes to
21+
* {@link $location#hash `$location.hash()`} and scroll to the element matching the new hash.<br />
2222
* Use this method to disable automatic scrolling.
2323
*
2424
* If automatic scrolling is disabled, one must explicitly call
25-
* {@link ng.$anchorScroll $anchorScroll()} in order to scroll to the element related to the
25+
* {@link $anchorScroll `$anchorScroll()`} in order to scroll to the element related to the
2626
* current hash.
2727
*/
2828
this.disableAutoScrolling = function() {
@@ -38,15 +38,15 @@ function $AnchorScrollProvider() {
3838
* @requires $rootScope
3939
*
4040
* @description
41-
* When called, it checks the current value of {@link ng.$location#hash $location.hash()} and
41+
* When called, it checks the current value of {@link $location#hash `$location.hash()`} and
4242
* scrolls to the related element, according to the rules specified in the
4343
* [Html5 spec](http://dev.w3.org/html5/spec/Overview.html#the-indicated-part-of-the-document).
4444
*
45-
* It also watches the {@link ng.$location#hash $location.hash()} and automatically scrolls to
45+
* It also watches the {@link $location#hash `$location.hash()`} and automatically scrolls to
4646
* match any anchor whenever it changes. This can be disabled by calling
47-
* {@link ng.$anchorScrollProvider#disableAutoScrolling $anchorScrollProvider.disableAutoScrolling()}.
47+
* {@link $anchorScrollProvider#disableAutoScrolling `$anchorScrollProvider.disableAutoScrolling()` }.
4848
*
49-
* Additionally, you can use its {@link ng.$anchorScroll#yOffset yOffset} property to specify a
49+
* Additionally, you can use its {@link $anchorScroll#yOffset `$anchorScroll.yOffset`} property to specify a
5050
* vertical scroll-offset (either fixed or dynamic).
5151
*
5252
* @property {(number|function|jqLite)} yOffset
@@ -225,6 +225,8 @@ function $AnchorScrollProvider() {
225225
var body = document.body;
226226
var bodyRect = body.getBoundingClientRect();
227227
var elemRect = elem.getBoundingClientRect();
228+
229+
228230
var necessaryOffset = offset - (elemRect.top - (bodyRect.top + body.scrollTop));
229231

230232
$window.scrollBy(0, -1 * necessaryOffset);

test/ng/anchorScrollSpec.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,6 @@ describe('$anchorScroll', function() {
258258
};
259259
}
260260

261-
beforeEach(inject(setupBodyForOffsetTesting()));
262-
263261
afterEach(inject(function($document) {
264262
dealoc($document);
265263
}));
@@ -269,18 +267,17 @@ describe('$anchorScroll', function() {
269267

270268
var yOffsetNumber = 50;
271269

272-
beforeEach(inject(
273-
setupBodyForOffsetTesting(),
274-
setYOffset(yOffsetNumber)));
275-
276-
277270
it('should scroll with vertical offset', inject(
271+
setupBodyForOffsetTesting(),
272+
setYOffset(yOffsetNumber),
278273
addElements('id=some'),
279274
changeHashTo('some'),
280275
expectScrollingWithOffset('id=some', yOffsetNumber)));
281276

282277

283278
it('should use the correct vertical offset when changing `yOffset` at runtime', inject(
279+
setupBodyForOffsetTesting(),
280+
setYOffset(yOffsetNumber),
284281
addElements('id=some'),
285282
changeHashTo('some'),
286283
setYOffset(yOffsetNumber - 10),
@@ -293,6 +290,8 @@ describe('$anchorScroll', function() {
293290
var targetAdjustedOffset = 25;
294291

295292
inject(
293+
setupBodyForOffsetTesting(),
294+
setYOffset(yOffsetNumber),
296295
addElements('id=some1', 'id=some2'),
297296
function($window) {
298297
// Make sure the elements are just a little shorter than the viewport height
@@ -334,6 +333,7 @@ describe('$anchorScroll', function() {
334333
}
335334

336335
inject(
336+
setupBodyForOffsetTesting(),
337337
addElements('id=id1', 'name=name2'),
338338
setYOffset(yOffsetFunction),
339339
changeHashTo('id1'),
@@ -371,6 +371,7 @@ describe('$anchorScroll', function() {
371371

372372

373373
it('should scroll with vertical offset when `top === 0`', inject(
374+
setupBodyForOffsetTesting(),
374375
createAndSetYOffsetElement({
375376
background: 'DarkOrchid',
376377
height: '50px',
@@ -383,6 +384,7 @@ describe('$anchorScroll', function() {
383384

384385

385386
it('should scroll with vertical offset when `top > 0`', inject(
387+
setupBodyForOffsetTesting(),
386388
createAndSetYOffsetElement({
387389
height: '50px',
388390
position: 'fixed',
@@ -394,6 +396,7 @@ describe('$anchorScroll', function() {
394396

395397

396398
it('should scroll without vertical offset when `position !== fixed`', inject(
399+
setupBodyForOffsetTesting(),
397400
createAndSetYOffsetElement({
398401
height: '50px',
399402
position: 'absolute',

0 commit comments

Comments
 (0)