Skip to content

Commit 5246813

Browse files
author
p01
committed
More review fixes
1 parent 4716f52 commit 5246813

File tree

2 files changed

+65
-65
lines changed

2 files changed

+65
-65
lines changed

src/resource-manager/resource_service.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -90,34 +90,34 @@ cls.ResourceInspector = function(network_logger)
9090
ctx.group_order = this.tree_view.get_group_order();
9191

9292
// get list of window_contexts for which we saw the main_document
93-
ctx.windowList = (this._network_logger.get_window_contexts() || []).filter(function(w) {
93+
ctx.window_list = (this._network_logger.get_window_contexts() || []).filter(function(w) {
9494
return w.saw_main_document;
9595
});
9696

97-
if (ctx.windowList.length)
97+
if (ctx.window_list.length)
9898
{
9999
// get all the (non-suppressed) resources with content
100-
ctx.resourceList = (this._network_logger.get_resources() || []).filter(function(v) {
100+
ctx.resource_list = (this._network_logger.get_resources() || []).filter(function(v) {
101101
return !this._suppress_uids.hasOwnProperty(v.uid) && v.responsecode != 204;
102102
}, this);
103103

104104
ctx.document_resource_hash = {};
105105

106106
// mapping of the WindowIDs in the debugging context
107107
var window_id_index = {};
108-
ctx.windowList.forEach(function(w, i) { window_id_index[w.id] = i; });
108+
ctx.window_list.forEach(function(w, i) { window_id_index[w.id] = i; });
109109

110110
var null_document_id = false;
111111
var document_id_index = {};
112112

113-
// filter the documentId that belong in the windowIdList,
113+
// filter the documents that belong in the window_id list,
114114
// set null_document_id flag,
115115
// augment the document objects,
116116
// set the default collapsed flags
117-
ctx.documentList = this._document_list.filter(function(d, i, a) {
118-
var inContext = window_id_index.hasOwnProperty(d.windowID);
117+
ctx.document_list = this._document_list.filter(function(d, i, a) {
118+
var in_context = window_id_index.hasOwnProperty(d.windowID);
119119

120-
if (inContext)
120+
if (in_context)
121121
{
122122
if (!null_document_id && !d.documentID)
123123
null_document_id = true;
@@ -129,7 +129,7 @@ cls.ResourceInspector = function(network_logger)
129129
document_id_index[d.documentID] = i;
130130

131131
// set depth, pivot_id and sameOrigin
132-
var p = a[document_id_index[d.parentDocumentID]] || {pivot_id:d.windowID, depth:0};
132+
var p = a[document_id_index[d.parentDocumentID]] || {pivot_id: d.windowID, depth: 0};
133133
var id = p.pivot_id + "_" + d.documentID;
134134
d.depth = p.depth + 1;
135135
d.pivot_id = id;
@@ -144,7 +144,7 @@ cls.ResourceInspector = function(network_logger)
144144
}
145145
}
146146

147-
return inContext;
147+
return in_context;
148148
}, this);
149149

150150
var unknown_document_id = false;
@@ -155,7 +155,7 @@ cls.ResourceInspector = function(network_logger)
155155
// sameOrigin flag to each resource,
156156
// full_id ( pivot_id + group + uid ),
157157
// pivot_id
158-
ctx.resourceList = ctx.resourceList.filter(function(r) {
158+
ctx.resource_list = ctx.resource_list.filter(function(r) {
159159
// check if this is the top resource of a document
160160
var document_id = ctx.document_resource_hash[r.resource_id];
161161
if (document_id != null && document_id != r.document_id)
@@ -180,27 +180,27 @@ cls.ResourceInspector = function(network_logger)
180180
}, this);
181181

182182
// sort the resource by their full_id ( pivot + uid )
183-
ctx.resourceList = ctx.resourceList.sort(function(a, b) {
183+
ctx.resource_list = ctx.resource_list.sort(function(a, b) {
184184
return a.full_id > b.full_id ? 1 : a.full_id == b.full_id ? 0 : -1;
185185
});
186186

187187
// filter the list of window. Purge the ones with no documents
188-
ctx.windowList = ctx.windowList.filter(function(v) {
189-
return ctx.documentList.some(function(w) {
188+
ctx.window_list = ctx.window_list.filter(function(v) {
189+
return ctx.document_list.some(function(w) {
190190
return v.id == w.windowID;
191191
});
192192
});
193193

194194

195195
// request the list of documents if we have
196-
// an empty documentList
196+
// an empty document_list
197197
// or a resource pointing to an unknown document
198198
// or a document does not have a document_id yet
199-
if (!ctx.documentList.length || unknown_document_id || null_document_id)
199+
if (!ctx.document_list.length || unknown_document_id || null_document_id)
200200
this._list_documents();
201201

202-
ctx.selectedResourceUID = this._selected_resource_uid;
203-
ctx.documentResources = this._document_resources;
202+
ctx._selected_resource_uid = this._selected_resource_uid;
203+
ctx.document_resources = this._document_resources;
204204
ctx.collapsed = this._collapsed_hash;
205205
this._context = ctx;
206206
}
@@ -288,7 +288,7 @@ cls.ResourceInspector = function(network_logger)
288288
// walk the list of resources in the "inc" direction, looking for the last visible
289289
// resource before we reached the selected resource uid ( or the end of the list )
290290
var uid;
291-
var list = this._context.resourceList;
291+
var list = this._context.resource_list;
292292
var i = inc < 0 ? list.length - 1 : 0;
293293

294294
while (list[i] != null && list[i].uid != this._selected_resource_uid)
@@ -374,7 +374,7 @@ cls.ResourceInspector = function(network_logger)
374374
if (!ctx)
375375
return null;
376376

377-
return ctx.resourceList.filter(function(v) { return v[key] == value; }).last;
377+
return ctx.resource_list.filter(function(v) { return v[key] == value; }).last;
378378
};
379379

380380
this.get_resource = function(uid)

src/resource-manager/resource_templates.js

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,18 @@ window.templates.resource_tree || (window.templates.resource_tree = new function
2525
var tpl = {};
2626

2727
tpl.h2 = ["handler", "resources-expand-collapse"];
28-
tpl.li =
29-
[
30-
"data-expand-collapse-id", pivot_id
31-
];
28+
tpl.li = ["data-expand-collapse-id", pivot_id];
3229
tpl.button =
3330
[
3431
"input",
35-
"type","button",
36-
"class","button-expand-collapse"+(collapsed ? "-close" : "")
32+
"type", "button",
33+
"class", "button-expand-collapse" + (collapsed ? "-close" : "")
3734
];
3835

3936
if (depth)
4037
tpl.button.push("style", "margin-left:" + depth * DEPTH_IDENTATION + "px;");
4138

42-
return {collapsed:collapsed, tpl:tpl};
39+
return {collapsed: collapsed, tpl: tpl};
4340
};
4441

4542
this.update = function(context)
@@ -52,7 +49,7 @@ window.templates.resource_tree || (window.templates.resource_tree = new function
5249

5350
// filter the list of resources, set their is_visible flag and push the ones matching
5451
context.resources = [];
55-
context.resourceList.forEach(function(r) {
52+
context.resource_list.forEach(function(r) {
5653
var matches = (context.search_term == "" || r.url.contains(context.search_term));
5754
r.is_visible = matches && !context.collapsed[r.pivot_id]
5855

@@ -68,13 +65,13 @@ window.templates.resource_tree || (window.templates.resource_tree = new function
6865

6966
this.windows = function(context)
7067
{
71-
context.windowList.forEach(this.window.bind(this, context));
68+
context.window_list.forEach(this.window.bind(this, context));
7269
};
7370

7471
this.window = function(context, w)
7572
{
76-
var windowInfo = window.window_manager_data.get_window(w.id);
77-
if (!windowInfo)
73+
var window_info = window.window_manager_data.get_window(w.id);
74+
if (!window_info)
7875
return [];
7976

8077
var extras = this._expander_extras(context, String(w.id));
@@ -84,7 +81,7 @@ window.templates.resource_tree || (window.templates.resource_tree = new function
8481
["h2",
8582
extras.tpl.button,
8683
["span",
87-
windowInfo.title,
84+
window_info.title,
8885
"class","resource-tree-window-label"
8986
]
9087
].concat(extras.tpl.h2),
@@ -97,18 +94,17 @@ window.templates.resource_tree || (window.templates.resource_tree = new function
9794

9895
this.documents = function(context, wid, pid)
9996
{
100-
context.documentList.filter(function(d) {
101-
return d.windowID == wid && d.parentDocumentID == pid;
102-
}).forEach(
103-
this.document.bind(this, context)
104-
);
97+
context.document_list.forEach(function(d) {
98+
if (d.windowID == wid && d.parentDocumentID == pid)
99+
this.document(context, d);
100+
}, this);
105101
};
106102

107103
this.document = function(context, d)
108104
{
109-
var documentResources = context.documentResources[d.documentID] || [];
105+
var document_resources = context.document_resources[d.documentID] || [];
110106
var resources = context.resources.filter(function(r) {
111-
return documentResources.contains(r.uid);
107+
return document_resources.contains(r.uid);
112108
});
113109

114110
var depth = d.depth;
@@ -196,8 +192,10 @@ window.templates.resource_tree || (window.templates.resource_tree = new function
196192
{
197193
var pos_first = r.url.indexOf(search) - URL_MATCH_CONTEXT_SIZE;
198194
var pos_last = r.url.lastIndexOf(search) + URL_MATCH_CONTEXT_SIZE + search.length;
195+
var preffix = pos_first > 0 ? "…" : "";
196+
var suffix = pos_last < r.url.length ? "…" : "";
199197

200-
partial_URL_match = (pos_first > 0 ? "…" : "") + r.url.substring(pos_first, pos_last) + (pos_last < r.url.length ? "…" : "");
198+
partial_URL_match = preffix + r.url.substring(pos_first, pos_last) + suffix;
201199
}
202200

203201
this.flat_list.push(
@@ -214,7 +212,7 @@ window.templates.resource_tree || (window.templates.resource_tree = new function
214212
r.sameOrigin ? [] : ["span", r.host, "class", "resource-domain"],
215213
"class", "resource-tree-resource"
216214
],
217-
"class", (context.selectedResourceUID == r.uid ? "resource-highlight" : ""),
215+
"class", (context.selected_resource_uid == r.uid ? "resource-highlight" : ""),
218216
"handler", "resource-detail",
219217
"data-resource-uid", String(r.uid)
220218
]
@@ -234,16 +232,16 @@ window.templates.resource_detail || (window.templates.resource_detail = new func
234232
if (!resource.data)
235233
return this.no_data_available(resource);
236234

237-
var specificTemplate = this[resource.type]?resource.type:"text";
235+
var specific_template = this[resource.type] ? resource.type : "text";
238236

239237
return(
240238
["div",
241-
this.overview(resource), // overview
242-
["div", // specific template
243-
this[specificTemplate](resource, resource.data),
244-
"class","resource-detail-"+ specificTemplate +"-container"
239+
this.overview(resource),
240+
["div",
241+
this[specific_template](resource, resource.data),
242+
"class", "resource-detail-" + specific_template + "-container"
245243
],
246-
"class","resource-detail-container"
244+
"class", "resource-detail-container"
247245
]);
248246
};
249247

@@ -252,7 +250,7 @@ window.templates.resource_detail || (window.templates.resource_detail = new func
252250
return(
253251
["div",
254252
ui_strings.S_RESOURCE_NO_RESOURCE_SELECTED,
255-
"class","resource-detail-container-empty"
253+
"class", "resource-detail-container-empty"
256254
]);
257255
};
258256

@@ -261,7 +259,7 @@ window.templates.resource_detail || (window.templates.resource_detail = new func
261259
return(
262260
["div",
263261
ui_strings.S_RESOURCE_NO_DATA_AVAILABLE,
264-
"class","resource-detail-container-empty"
262+
"class", "resource-detail-container-empty"
265263
]);
266264
};
267265

@@ -276,7 +274,7 @@ window.templates.resource_detail || (window.templates.resource_detail = new func
276274
return(
277275
["div",
278276
ui_strings.S_RESOURCE_FORMATTING_RESOURCE,
279-
"class","resource-detail-container-empty"
277+
"class", "resource-detail-container-empty"
280278
]);
281279
};
282280

@@ -304,18 +302,18 @@ window.templates.resource_detail || (window.templates.resource_detail = new func
304302
"class", "resource-detail-overview-url"
305303
],
306304
["span",
307-
(isError ? info.responseCode + " - " : "")+
305+
(isError ? info.responseCode + " - " : "") +
308306
ui_strings.S_RESOURCE_SENT_AND_GUESSED_TYPE
309307
.replace("%(SENT)s", resource.data.mimeType)
310-
.replace("%(GUESSED)s", resource.type)
311-
+(info.characterEncoding && " " + ui_strings.S_RESOURCE_ENCODING.replace("%s", info.characterEncoding)),
308+
.replace("%(GUESSED)s", resource.type) +
309+
(info.characterEncoding && " " + ui_strings.S_RESOURCE_ENCODING.replace("%s", info.characterEncoding)),
312310
"class", "resource-detail-overview-type" + (isError ? " resource-detail-error" : "")
313311
],
314312
["span",
315-
cls.ResourceUtil.bytes_to_human_readable(info.size)
316-
+(resource.data.meta ? " (" + resource.data.meta + ")" : ""),
313+
cls.ResourceUtil.bytes_to_human_readable(info.size) +
314+
(resource.data.meta ? " (" + resource.data.meta + ")" : ""),
317315
"data-tooltip", "js-script-select",
318-
"data-tooltip-text", info.size + " bytes",
316+
"data-tooltip-text", info.size + " " + ui_strings.S_BYTES_UNIT,
319317
"class", "resource-detail-overview-size"
320318
],
321319
"class", "resource-detail-overview"
@@ -326,9 +324,9 @@ window.templates.resource_detail || (window.templates.resource_detail = new func
326324
{
327325
var data = resource.data.content.stringData;
328326
var pos = data.indexOf(",");
329-
var base64 = data.lastIndexOf(";base64", pos) != -1;
327+
var is_base64 = data.lastIndexOf(";base64", pos) != -1;
330328

331-
return ["pre", base64?atob(data.slice(pos + 1)) : data.slice(pos + 1)];
329+
return ["pre", is_base64 ? atob(data.slice(pos + 1)) : data.slice(pos + 1)];
332330
};
333331

334332
this.markup = function(resource)
@@ -375,16 +373,18 @@ window.templates.resource_detail || (window.templates.resource_detail = new func
375373

376374
this.font = function(resource)
377375
{
378-
var styleRule = "@font-face{font-family:\"resource-" + resource.id + "\";src:url(\"" + resource.data.content.stringData + "\");}";
376+
var font_face = "@font-face{font-family:\"resource-" + resource.uid + "\";src:url(\"" + resource.data.content.stringData + "\");}";
377+
var inline_style = "font-size:64px;font-family:resource-" + resource.uid + ";";
378+
var sample_string = "The quick brown fox jumps over the lazy dog 0123456789";
379379

380380
return(
381381
["object",
382382
["div",
383-
"The quick brown fox jumps over the lazy dog 0123456789",
384-
["style", styleRule],
385-
"style", "font-family:resource-" + resource.id
383+
sample_string,
384+
["style", font_face],
385+
"style", inline_style,
386386
],
387-
"data", "data:text/html;base64," + btoa("<!doctype html><style>" + styleRule + "</style><div contenteditable=\"true\" style=\"font-size:64px;margin:0;font-family:resource-" + resource.id + ";\">The quick brown fox jumps over the lazy dog 0123456789"),
387+
"data", "data:text/html;base64," + btoa("<!doctype html><style>" + font_face + "</style><div contenteditable=\"true\" style=\"" + inline_style + "\">" + sample_string),
388388
"class", "resource-detail-font"
389389
]);
390390
};
@@ -396,7 +396,7 @@ window.templates.resource_detail || (window.templates.resource_detail = new func
396396
["div",
397397
"Type not supported"
398398
],
399-
"type", "resource.mimeType",
399+
"type", resource.mimeType,
400400
"data", resource.data.content.stringData,
401401
"class", "resource-detail-flash"
402402
]);
@@ -407,7 +407,7 @@ window.templates.resource_detail || (window.templates.resource_detail = new func
407407
return (
408408
["img",
409409
"src", resource.data.content.stringData,
410-
"class","resource-detail-image"
410+
"class", "resource-detail-image"
411411
]);
412412
};
413413
});

0 commit comments

Comments
 (0)