@@ -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 >
@@ -77,11 +78,11 @@ <h2 class="panel-title">
77
78
< span ng-if ="lint.level == 'Deny' " class ="label label-danger "> Deny</ span >
78
79
< span ng-if ="lint.level == 'Deprecated' " class ="label label-default "> Deprecated</ span >
79
80
80
- < a href ="#{{lint.id}} " class ="anchor label label-default "> ¶</ a >
81
+ < a href ="#{{lint.id}} " class ="anchor label label-default " ng-click =" open[lint.id] = true; $event.stopPropagation() " > ¶</ a >
81
82
</ h2 >
82
83
</ header >
83
84
84
- < ul class ="list-group " ng-if ="lint.docs " ng-class ="{collapse: true, in: open[lint.id]} ">
85
+ < ul class ="list-group lint-docs " ng-if ="lint.docs " ng-class ="{collapse: true, in: open[lint.id]} ">
85
86
< li class ="list-group-item " ng-repeat ="(title, text) in lint.docs ">
86
87
< h4 class ="list-group-item-heading ">
87
88
{{title}}
@@ -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 >
@@ -120,6 +121,21 @@ <h4 class="list-group-item-heading">
120
121
}
121
122
} ) ;
122
123
124
+ function scrollToLint ( lintId ) {
125
+ var target = document . getElementById ( lintId ) ;
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
+ } ) ;
137
+ }
138
+
123
139
angular . module ( "clippy" , [ ] )
124
140
. filter ( 'markdown' , function ( $sce ) {
125
141
return function ( text ) {
@@ -130,9 +146,22 @@ <h4 class="list-group-item-heading">
130
146
) ;
131
147
} ;
132
148
} )
133
- . controller ( "lintList" , function ( $scope , $http ) {
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
+ } )
161
+ . controller ( "lintList" , function ( $scope , $http , $timeout ) {
134
162
// Level filter
135
- $scope . levels = { Allow : true , Warn : true , Deny : true , Deprecated : true } ;
163
+ var LEVEL_FILTERS_DEFAULT = { Allow : true , Warn : true , Deny : true , Deprecated : true } ;
164
+ $scope . levels = LEVEL_FILTERS_DEFAULT ;
136
165
$scope . byLevels = function ( lint ) {
137
166
return $scope . levels [ lint . level ] ;
138
167
} ;
@@ -141,17 +170,37 @@ <h4 class="list-group-item-heading">
141
170
$scope . open = { } ;
142
171
$scope . loading = true ;
143
172
173
+ if ( window . location . hash . length > 1 ) {
174
+ $scope . search = window . location . hash . slice ( 1 ) ;
175
+ $scope . open [ window . location . hash . slice ( 1 ) ] = true ;
176
+ scrollToLintByURL ( $scope ) ;
177
+ }
178
+
144
179
$http . get ( './lints.json' )
145
180
. success ( function ( data ) {
146
181
$scope . data = data ;
147
182
$scope . loading = false ;
183
+
184
+ scrollToLintByURL ( $scope ) ;
148
185
} )
149
186
. error ( function ( data ) {
150
187
$scope . error = data ;
151
188
$scope . loading = false ;
152
189
} ) ;
153
- } )
190
+
191
+ window . addEventListener ( 'hashchange' , function ( ) {
192
+ // trigger re-render
193
+ $timeout ( function ( ) {
194
+ $scope . levels = LEVEL_FILTERS_DEFAULT ;
195
+ $scope . search = window . location . hash . slice ( 1 ) ;
196
+ $scope . open [ window . location . hash . slice ( 1 ) ] = true ;
197
+
198
+ scrollToLintByURL ( $scope ) ;
199
+ } ) ;
200
+ return true ;
201
+ } , false ) ;
202
+ } ) ;
154
203
} ) ( ) ;
155
204
</ script >
156
205
</ body >
157
- </ html >
206
+ </ html >
0 commit comments