@@ -77,11 +77,11 @@ <h2 class="panel-title">
77
77
< span ng-if ="lint.level == 'Deny' " class ="label label-danger "> Deny</ span >
78
78
< span ng-if ="lint.level == 'Deprecated' " class ="label label-default "> Deprecated</ span >
79
79
80
- < a href ="#{{lint.id}} " class ="anchor label label-default "> ¶</ a >
80
+ < a href ="#{{lint.id}} " class ="anchor label label-default " ng-click =" open[lint.id] = true; $event.stopPropagation() " > ¶</ a >
81
81
</ h2 >
82
82
</ header >
83
83
84
- < ul class ="list-group " ng-if ="lint.docs " ng-class ="{collapse: true, in: open[lint.id]} ">
84
+ < ul class ="list-group lint-docs " ng-if ="lint.docs " ng-class ="{collapse: true, in: open[lint.id]} ">
85
85
< li class ="list-group-item " ng-repeat ="(title, text) in lint.docs ">
86
86
< h4 class ="list-group-item-heading ">
87
87
{{title}}
@@ -120,6 +120,12 @@ <h4 class="list-group-item-heading">
120
120
}
121
121
} ) ;
122
122
123
+ function scrollToLint ( lintId ) {
124
+ var target = document . getElementById ( lintId ) ;
125
+ if ( ! target ) { return ; }
126
+ document . body . scrollTop = target . offsetTop ;
127
+ }
128
+
123
129
angular . module ( "clippy" , [ ] )
124
130
. filter ( 'markdown' , function ( $sce ) {
125
131
return function ( text ) {
@@ -130,9 +136,10 @@ <h4 class="list-group-item-heading">
130
136
) ;
131
137
} ;
132
138
} )
133
- . controller ( "lintList" , function ( $scope , $http ) {
139
+ . controller ( "lintList" , function ( $scope , $http , $timeout ) {
134
140
// Level filter
135
- $scope . levels = { Allow : true , Warn : true , Deny : true , Deprecated : true } ;
141
+ var LEVEL_FILTERS_DEFAULT = { Allow : true , Warn : true , Deny : true , Deprecated : true } ;
142
+ $scope . levels = LEVEL_FILTERS_DEFAULT ;
136
143
$scope . byLevels = function ( lint ) {
137
144
return $scope . levels [ lint . level ] ;
138
145
} ;
@@ -141,16 +148,37 @@ <h4 class="list-group-item-heading">
141
148
$scope . open = { } ;
142
149
$scope . loading = true ;
143
150
151
+ if ( window . location . hash . length > 1 ) {
152
+ $scope . open [ window . location . hash . slice ( 1 ) ] = true ;
153
+ }
154
+
144
155
$http . get ( './lints.json' )
145
156
. success ( function ( data ) {
146
157
$scope . data = data ;
147
158
$scope . loading = false ;
159
+
160
+ $timeout ( function ( ) {
161
+ scrollToLint ( window . location . hash . slice ( 1 ) ) ;
162
+ } , 100 ) ;
148
163
} )
149
164
. error ( function ( data ) {
150
165
$scope . error = data ;
151
166
$scope . loading = false ;
152
167
} ) ;
153
- } )
168
+
169
+ window . addEventListener ( 'hashchange' , function ( ) {
170
+ // trigger re-render
171
+ $timeout ( function ( ) {
172
+ $scope . search = "" ;
173
+ $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 ) ;
178
+ } ) ;
179
+ return true ;
180
+ } , false ) ;
181
+ } ) ;
154
182
} ) ( ) ;
155
183
</ script >
156
184
</ body >
0 commit comments