@@ -7,6 +7,9 @@ window.cls || (window.cls = {});
77 */
88cls . ResourceInspector = function ( network_logger )
99{
10+ var EXPAND_COLLAPSE_ATTRIBUTE = "data-expand-collapse-id" ;
11+ var RESOURCE_UID_ATTRIBUTE = "data-resource-uid" ;
12+ var HIGHLIGHT_CLASSNAME = "resource-highlight" ;
1013
1114 var THROTTLE_DELAY = 250 ;
1215 var TYPE_GROUP_MAPPING =
@@ -125,11 +128,11 @@ cls.ResourceInspector = function(network_logger)
125128 // populate document_id_index
126129 document_id_index [ d . documentID ] = i ;
127130
128- // set depth, pivotID and sameOrigin
129- var p = a [ document_id_index [ d . parentDocumentID ] ] || { pivotID :d . windowID , depth :0 } ;
130- var id = p . pivotID + "_" + d . documentID ;
131+ // set depth, pivot_id and sameOrigin
132+ var p = a [ document_id_index [ d . parentDocumentID ] ] || { pivot_id :d . windowID , depth :0 } ;
133+ var id = p . pivot_id + "_" + d . documentID ;
131134 d . depth = p . depth + 1 ;
132- d . pivotID = id ;
135+ d . pivot_id = id ;
133136 d . sameOrigin = cls . ResourceUtil . sameOrigin ( p . url , d . url ) ;
134137
135138 // set the default collapsed flag
@@ -145,33 +148,40 @@ cls.ResourceInspector = function(network_logger)
145148 } , this ) ;
146149
147150 var unknown_document_id = false ;
148-
151+ // filter out resources pointing to an unknown document_id,
149152 // set unknown_document_id flag,
150153 // assign top resource to the right document,
151154 // add group to each resource,
152- // sameOrigin flag to each resource
153- // full_id ( pivot_ID + uid )
154- ctx . resourceList . forEach ( function ( r ) {
155- if ( ! unknown_document_id && ! document_id_index . hasOwnProperty ( r . document_id ) )
156- unknown_document_id = true ;
157-
155+ // sameOrigin flag to each resource,
156+ // full_id ( pivot_id + group + uid ),
157+ // pivot_id
158+ ctx . resourceList = ctx . resourceList . filter ( function ( r ) {
158159 // check if this is the top resource of a document
159- var documentID = ctx . document_resource_hash [ r . resource_id ] ;
160- if ( documentID != null && documentID != r . document_id )
161- r . document_id = documentID ;
160+ var document_id = ctx . document_resource_hash [ r . resource_id ] ;
161+ if ( document_id != null && document_id != r . document_id )
162+ r . document_id = document_id ;
163+
164+ var d = this . _document_list [ document_id_index [ r . document_id ] ] ;
165+ if ( ! d )
166+ {
167+ unknown_document_id = true ;
168+ return false ;
169+ }
162170
163171 this . _populate_document_resources ( r ) ;
164172
165173 r . group = TYPE_GROUP_MAPPING [ r . type ] || TYPE_GROUP_MAPPING [ "*" ] ;
166- var d = this . _document_list [ document_id_index [ r . document_id ] ] ;
167- r . sameOrigin = cls . ResourceUtil . sameOrigin ( d && d . url , r ) ;
168- r . full_id = ( d && d . pivotID ) + "_" + ctx . group_order . indexOf ( r . group ) + r . group + "_" + r . uid ;
174+ r . sameOrigin = cls . ResourceUtil . sameOrigin ( d . url , r ) ;
175+
176+ r . full_id = d . pivot_id + "_" + ctx . group_order . indexOf ( r . group ) + r . group + "_" + r . uid ;
177+ r . pivot_id = d . pivot_id + "_" + r . group ;
169178
179+ return true ;
170180 } , this ) ;
171181
172182 // sort the resource by their full_id ( pivot + uid )
173183 ctx . resourceList = ctx . resourceList . sort ( function ( a , b ) {
174- return a . full_uid > b . full_uid ? 1 : a . full_uid == b . full_uid ? 0 : - 1 ;
184+ return a . full_id > b . full_id ? 1 : a . full_id == b . full_id ? 0 : - 1 ;
175185 } ) ;
176186
177187 // filter the list of window. Purge the ones with no documents
@@ -185,7 +195,7 @@ cls.ResourceInspector = function(network_logger)
185195 // request the list of documents if we have
186196 // an empty documentList
187197 // or a resource pointing to an unknown document
188- // or a document does not have a documentID yet
198+ // or a document does not have a document_id yet
189199 if ( ! ctx . documentList . length || unknown_document_id || null_document_id )
190200 this . _list_documents ( ) ;
191201
@@ -214,22 +224,22 @@ cls.ResourceInspector = function(network_logger)
214224 if ( ! this . _context )
215225 return ;
216226
217- var pivot = target . get_ancestor ( "[data-expand-collapse-id ]" ) ;
227+ var pivot = target . get_ancestor ( "[" + EXPAND_COLLAPSE_ATTRIBUTE + " ]") ;
218228 if ( pivot )
219229 {
220230 var hash = this . _collapsed_hash ;
221- var pivotID = pivot . getAttribute ( "data-expand-collapse-id" ) ;
222- var pivotIDs = [ pivotID ] ;
223- var collapsed = ! hash [ pivotID ] ;
231+ var pivot_id = pivot . getAttribute ( EXPAND_COLLAPSE_ATTRIBUTE ) ;
232+ var pivot_ids = [ pivot_id ] ;
233+ var collapsed = ! hash [ pivot_id ] ;
224234
225235 if ( event . shiftKey )
226236 {
227- pivotIDs . push . apply ( pivotIDs , Object . keys ( hash ) . filter ( function ( p ) {
228- return p . startswith ( pivotID + "_" ) ;
237+ pivot_ids . push . apply ( pivot_ids , Object . keys ( hash ) . filter ( function ( p ) {
238+ return p . startswith ( pivot_id + "_" ) ;
229239 } ) ) ;
230240 }
231241
232- pivotIDs . forEach ( function ( p ) { hash [ p ] = collapsed ; } ) ;
242+ pivot_ids . forEach ( function ( p ) { hash [ p ] = collapsed ; } ) ;
233243
234244 this . tree_view . update ( ) ;
235245 }
@@ -240,59 +250,70 @@ cls.ResourceInspector = function(network_logger)
240250 if ( ! this . _context )
241251 return ;
242252
243- var parent = target . get_ancestor ( "[data-resource-uid ]" ) ;
253+ var parent = target . get_ancestor ( "[" + RESOURCE_UID_ATTRIBUTE + " ]") ;
244254 if ( parent == null )
245255 return ;
246256
247- var uid = parent . getAttribute ( "data-resource-uid" ) ;
257+ var uid = parent . getAttribute ( RESOURCE_UID_ATTRIBUTE ) ;
248258 this . highlight_resource ( uid ) ;
249259 this . detail_view . show_resource ( uid ) ;
250260 } . bind ( this ) ;
251261
252262 this . highlight_resource = function ( uid )
253263 {
254- var e ;
255264 if ( this . _selected_resource_uid == uid )
256265 return ;
257266
258- e = document . querySelector ( ".resource-highlight" ) ;
267+ var e = document . querySelector ( "." + HIGHLIGHT_CLASSNAME ) ;
259268 if ( e )
260- e . removeClass ( "resource-highlight" ) ;
269+ e . removeClass ( HIGHLIGHT_CLASSNAME ) ;
261270
262271 this . _selected_resource_uid = uid ;
263272 if ( this . _context )
264273 this . _context . selectedResourceUID = uid ;
265274
266- e = document . querySelector ( "[data-resource-uid ='" + this . _selected_resource_uid + "']" ) ;
275+ e = document . querySelector ( "[" + RESOURCE_UID_ATTRIBUTE + " ='" + this . _selected_resource_uid + "']" ) ;
267276 if ( e )
268- e . addClass ( "resource-highlight" ) ;
277+ {
278+ e . addClass ( HIGHLIGHT_CLASSNAME ) ;
279+ // todo: scroll into view
280+ }
269281 } . bind ( this ) ;
270282
271- this . _highlight_sibling_resource = function ( increment )
283+ this . _highlight_sibling_resource = function ( inc )
272284 {
273- if ( ! this . _context || ! this . _context . visibleResources || ! this . _context . visibleResources . length )
285+ if ( ! this . _context )
274286 return ;
275287
288+ // walk the list of resources in the "inc" direction, looking for the last visible
289+ // resource before we reached the selected resource uid ( or the end of the list )
276290 var uid ;
277- var list = this . _context . visibleResources ;
278- var pos = list . indexOf ( this . _selected_resource_uid ) ;
279- if ( pos == - 1 )
280- uid = list [ increment > 0 ? 0 : list . length - 1 ] ;
281- else
282- uid = list [ Math . min ( Math . max ( 0 , pos + increment ) , list . length - 1 ) ] ;
291+ var list = this . _context . resourceList ;
292+ var i = inc < 0 ? list . length - 1 : 0 ;
283293
284- this . highlight_resource ( uid ) ;
294+ while ( list [ i ] != null && list [ i ] . uid != this . _selected_resource_uid )
295+ {
296+ if ( list [ i ] . is_visible )
297+ uid = list [ i ] . uid ;
298+
299+ i += inc ;
300+ }
301+
302+ if ( uid != null )
303+ {
304+ this . highlight_resource ( uid ) ;
285305 this . detail_view . show_resource ( uid ) ;
306+ }
286307 } ;
287308
288309 this . highlight_next_resource_bound = function ( )
289310 {
290- this . _highlight_sibling_resource ( 1 ) ;
311+ this . _highlight_sibling_resource ( - 1 ) ;
291312 } . bind ( this ) ;
292313
293314 this . highlight_previous_resource_bound = function ( )
294315 {
295- this . _highlight_sibling_resource ( - 1 ) ;
316+ this . _highlight_sibling_resource ( 1 ) ;
296317 } . bind ( this ) ;
297318
298319 this . _resource_request_update_bound = function ( msg )
0 commit comments