@@ -62,7 +62,8 @@ <h1>ALL the Clippy Lints</h1>
62
62
</ div >
63
63
</ div >
64
64
65
- < article class ="panel panel-default " id ="{{lint.id}} " ng-repeat ="lint in data | filter:byLevels | filter:search | orderBy:'id' track by lint.id ">
65
+ < article class ="panel panel-default " id ="{{lint.id}} "
66
+ ng-repeat ="lint in data | filter:byLevels | filter:search | orderBy:'id' track by lint.id " on-finish-render ="ngRepeatFinished ">
66
67
< header class ="panel-heading " ng-click ="open[lint.id] = !open[lint.id] ">
67
68
< button class ="btn btn-default btn-sm pull-right " style ="margin-top: -6px; ">
68
69
< span ng-show ="open[lint.id] "> −</ span >
@@ -96,7 +97,7 @@ <h4 class="list-group-item-heading">
96
97
< a href ="https://github.com/Manishearth/rust-clippy ">
97
98
< img style ="position: absolute; top: 0; right: 0; border: 0; " src ="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png "/>
98
99
</ a >
99
-
100
+
100
101
< script src ="https://cdnjs.cloudflare.com/ajax/libs/markdown-it/7.0.0/markdown-it.min.js "> </ script >
101
102
< script src ="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.5.0/highlight.min.js "> </ script >
102
103
< script src ="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.5.0/languages/rust.min.js "> </ script >
@@ -122,8 +123,17 @@ <h4 class="list-group-item-heading">
122
123
123
124
function scrollToLint ( lintId ) {
124
125
var target = document . getElementById ( lintId ) ;
125
- if ( ! target ) { return ; }
126
- document . body . scrollTop = target . offsetTop ;
126
+ if ( ! target ) {
127
+ return ;
128
+ }
129
+ target . scrollIntoView ( ) ;
130
+ }
131
+
132
+ function scrollToLintByURL ( $scope ) {
133
+ var removeListener = $scope . $on ( 'ngRepeatFinished' , function ( ngRepeatFinishedEvent ) {
134
+ scrollToLint ( window . location . hash . slice ( 1 ) ) ;
135
+ removeListener ( ) ;
136
+ } ) ;
127
137
}
128
138
129
139
angular . module ( "clippy" , [ ] )
@@ -136,6 +146,18 @@ <h4 class="list-group-item-heading">
136
146
) ;
137
147
} ;
138
148
} )
149
+ . directive ( 'onFinishRender' , function ( $timeout ) {
150
+ return {
151
+ restrict : 'A' ,
152
+ link : function ( scope , element , attr ) {
153
+ if ( scope . $last === true ) {
154
+ $timeout ( function ( ) {
155
+ scope . $emit ( attr . onFinishRender ) ;
156
+ } ) ;
157
+ }
158
+ }
159
+ } ;
160
+ } )
139
161
. controller ( "lintList" , function ( $scope , $http , $timeout ) {
140
162
// Level filter
141
163
var LEVEL_FILTERS_DEFAULT = { Allow : true , Warn : true , Deny : true , Deprecated : true } ;
@@ -149,17 +171,17 @@ <h4 class="list-group-item-heading">
149
171
$scope . loading = true ;
150
172
151
173
if ( window . location . hash . length > 1 ) {
174
+ $scope . search = window . location . hash . slice ( 1 ) ;
152
175
$scope . open [ window . location . hash . slice ( 1 ) ] = true ;
176
+ scrollToLintByURL ( $scope ) ;
153
177
}
154
178
155
179
$http . get ( './lints.json' )
156
180
. success ( function ( data ) {
157
181
$scope . data = data ;
158
182
$scope . loading = false ;
159
183
160
- $timeout ( function ( ) {
161
- scrollToLint ( window . location . hash . slice ( 1 ) ) ;
162
- } , 100 ) ;
184
+ scrollToLintByURL ( $scope ) ;
163
185
} )
164
186
. error ( function ( data ) {
165
187
$scope . error = data ;
@@ -169,17 +191,16 @@ <h4 class="list-group-item-heading">
169
191
window . addEventListener ( 'hashchange' , function ( ) {
170
192
// trigger re-render
171
193
$timeout ( function ( ) {
172
- $scope . search = "" ;
173
194
$scope . levels = LEVEL_FILTERS_DEFAULT ;
174
- // quick n dirty: wait for re-render to finish
175
- $timeout ( function ( ) {
176
- scrollToLint ( window . location . hash . slice ( 1 ) ) ;
177
- } , 100 ) ;
195
+ $scope . search = window . location . hash . slice ( 1 ) ;
196
+ $scope . open [ window . location . hash . slice ( 1 ) ] = true ;
197
+
198
+ scrollToLintByURL ( $scope ) ;
178
199
} ) ;
179
200
return true ;
180
201
} , false ) ;
181
202
} ) ;
182
203
} ) ( ) ;
183
204
</ script >
184
205
</ body >
185
- </ html >
206
+ </ html >
0 commit comments