Skip to content

Commit 7abf5a8

Browse files
author
p01
committed
fixed some contentLength/size/length mismatch, added .go_to_line in cls.ResourceDetailView.instance.createView
1 parent 2c575b3 commit 7abf5a8

File tree

5 files changed

+276
-146
lines changed

5 files changed

+276
-146
lines changed
Lines changed: 133 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -1,142 +1,151 @@
11
window.cls || (window.cls = {});
22

3-
cls.OpenSingleResource = function(view,manager, url, data)
3+
cls.OpenSingleResource = function(view, manager, url, data)
44
{
5-
this._view = view;
6-
this._manager = manager;
7-
this._url = url;
8-
this._data = data;
9-
10-
if (!this._tagman)
11-
{
12-
this._init_prototype();
13-
}
14-
this._show_resource();
5+
this._view = view;
6+
this._manager = manager;
7+
this._url = url;
8+
this._data = data;
9+
10+
if (!this._tagman)
11+
{
12+
this._init_prototype();
13+
}
14+
this._show_resource();
1515
};
1616

1717
cls.OpenSingleResource.prototype = new function()
1818
{
19-
const
20-
TRANSPORT_STRING = 1,
21-
TRANSPORT_DATA_URI = 3,
22-
DECODE_TRUE = 1,
23-
SIZE_LIMIT = 1e7,
24-
TRANSPORT_OFF = 4;
19+
const
20+
TRANSPORT_STRING = 1,
21+
TRANSPORT_DATA_URI = 3,
22+
DECODE_TRUE = 1,
23+
SIZE_LIMIT = 1e7,
24+
TRANSPORT_OFF = 4;
2525

26-
this._show_resource = function()
27-
{
28-
if (!this._manager.get_resource_for_url(this._url))
29-
//if (!this._view.show_resource_for_url(this._url, this._data))
30-
{
31-
if (this._service.requestGetResourceID)
32-
{
33-
var tag = this._tagman.set_callback(this, this._on_resolve_url);
34-
this._service.requestGetResourceID(tag, [this._url]);
35-
}
36-
else
37-
{
38-
this._fallback();
39-
}
40-
}
41-
};
26+
this._show_resource = function()
27+
{
28+
if (!this._manager.get_resource_for_url(this._url))
29+
{
30+
if (this._service.requestGetResourceID)
31+
{
32+
var tag = this._tagman.set_callback(this, this._on_resolve_url);
33+
this._service.requestGetResourceID(tag, [this._url]);
34+
}
35+
else
36+
{
37+
this._fallback();
38+
}
39+
}
40+
};
4241

43-
this._on_resolve_url = function(status, message)
44-
{
45-
if (status)
46-
{
47-
if (this._service.requestCreateRequest)
48-
{
49-
var debugContext = window.window_manager_data.get_debug_context();
50-
var tag = this._tagman.set_callback(this, this._on_resolve_url_request);
51-
this._service.requestCreateRequest(tag, [debugContext, this._url, 'GET']);
52-
}
53-
else
54-
{
55-
this._fallback();
56-
}
57-
}
58-
else
59-
{
60-
const RESOURCE_ID = 0;
61-
this._rid = message[RESOURCE_ID];
42+
this._requestResource = function(id)
43+
{
44+
const RESOURCE_ID = 0;
45+
this._rid = message[RESOURCE_ID];
6246
// if (!this._view.show_resource_for_id(this._rid))
63-
{
64-
var tag = this._tagman.set_callback(this, this._on_mime_type);
65-
this._service.requestGetResource(tag, [this._rid, [TRANSPORT_OFF]]);
66-
}
67-
}
68-
};
47+
{
48+
var tag = this._tagman.set_callback(this, this._on_mime_type);
49+
this._service.requestGetResource(tag, [this._rid, [TRANSPORT_OFF]]);
50+
}
51+
}
6952

70-
this._on_resolve_url_request = function(status, message)
71-
{
72-
if (status)
73-
{
74-
this._fallback();
75-
}
76-
else
77-
{
78-
const RESOURCE_ID = 0;
79-
this._rid = message[RESOURCE_ID];
53+
this._on_resolve_url = function(status, message)
54+
{
55+
if (status)
56+
{
57+
if (this._service.requestCreateRequest)
58+
{
59+
var debugContext = window.window_manager_data.get_debug_context();
60+
var tag = this._tagman.set_callback(this, this._on_resolve_url_request);
61+
this._service.requestCreateRequest(tag, [debugContext, this._url, 'GET']);
62+
}
63+
else
64+
{
65+
this._fallback();
66+
}
67+
}
68+
else
69+
{
70+
const RESOURCE_ID = 0;
71+
this._rid = message[RESOURCE_ID];
8072
// if (!this._view.show_resource_for_id(this._rid))
81-
{
82-
var tag = this._tagman.set_callback(this, this._on_mime_type);
83-
this._service.requestGetResource(tag, [this._rid, [TRANSPORT_OFF]]);
84-
}
85-
}
86-
};
73+
{
74+
var tag = this._tagman.set_callback(this, this._on_mime_type);
75+
this._service.requestGetResource(tag, [this._rid, [TRANSPORT_OFF]]);
76+
}
77+
}
78+
};
8779

88-
this._on_mime_type = function(status, message)
89-
{
90-
if (status)
91-
{
92-
this._fallback();
93-
}
94-
else
95-
{
96-
this._res = new cls.Resource(this._rid);
97-
this._res.update("urlfinished", new this._ResourceData(message));
98-
var resptype = this._utils.mime_to_content_mode(this._res.mime);
99-
var tag = this._tagman.set_callback(this, this._on_resource);
100-
var msg =
101-
[
102-
this._rid,
103-
[
104-
resptype == "datauri" ? TRANSPORT_DATA_URI : TRANSPORT_STRING,
105-
DECODE_TRUE,
106-
SIZE_LIMIT
107-
]
108-
];
109-
this._service.requestGetResource(tag, msg);
110-
}
111-
};
112-
.001
80+
this._on_resolve_url_request = function(status, message)
81+
{
82+
if (status)
83+
{
84+
this._fallback();
85+
}
86+
else
87+
{
88+
const RESOURCE_ID = 0;
89+
this._rid = message[RESOURCE_ID];
90+
// if (!this._view.show_resource_for_id(this._rid))
91+
{
92+
var tag = this._tagman.set_callback(this, this._on_mime_type);
93+
this._service.requestGetResource(tag, [this._rid, [TRANSPORT_OFF]]);
94+
}
95+
}
96+
};
97+
98+
this._on_mime_type = function(status, message)
99+
{
100+
if (status)
101+
{
102+
this._fallback();
103+
}
104+
else
105+
{
106+
this._res = new cls.Resource(this._rid);
107+
this._res.update("urlfinished", new this._ResourceData(message));
108+
var resptype = this._utils.mime_to_content_mode(this._res.mime);
109+
var tag = this._tagman.set_callback(this, this._on_resource);
110+
var msg =
111+
[
112+
this._rid,
113+
[
114+
resptype == "datauri" ? TRANSPORT_DATA_URI : TRANSPORT_STRING,
115+
DECODE_TRUE,
116+
SIZE_LIMIT
117+
]
118+
];
119+
this._service.requestGetResource(tag, msg);
120+
}
121+
};
113122

114-
this._on_resource = function(status, message)
115-
{
116-
if (status)
117-
{
118-
this._fallback();
119-
}
120-
else
121-
{
122-
//this._res.update("urlfinished", new this._ResourceData(message));
123-
this._res.update("responsefinished", message );
124-
this._view.open_resource_tab(this._res, this._data);
125-
window.UI.instance.show_view( this._view.id );
126-
}
127-
};
123+
this._on_resource = function(status, message)
124+
{
125+
if (status)
126+
{
127+
this._fallback();
128+
}
129+
else
130+
{
131+
//this._res.update("urlfinished", new this._ResourceData(message));
132+
this._res.update("responsefinished", message );
133+
this._view.open_resource_tab(this._res, this._data);
134+
window.UI.instance.show_view( this._view.id );
135+
}
136+
};
128137

129-
this._fallback = function()
130-
{
131-
window.open(this._url);
132-
};
138+
this._fallback = function()
139+
{
140+
window.open(this._url);
141+
};
133142

134-
this._init_prototype = function()
135-
{
136-
this._tagman = window.tagManager;
137-
this._service = window.services['resource-manager'];
138-
this._ResourceData = cls.ResourceManager["1.0"].ResourceData;
139-
this._utils = cls.ResourceUtil;
140-
}.bind(this);
143+
this._init_prototype = function()
144+
{
145+
this._tagman = window.tagManager;
146+
this._service = window.services['resource-manager'];
147+
this._ResourceData = cls.ResourceManager["1.0"].ResourceData;
148+
this._utils = cls.ResourceUtil;
149+
}.bind(this);
141150

142151
};

src/resource-manager/resource_base.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ cls.ResourceDetailBase = function()
1919
this._span.textContent = ' ';
2020
this._line_count = 0;
2121
this._line_found = false;
22-
this._line = 0;
22+
this._target_line = 0;
2323
this._root_ele = null;
2424
this._tops = [];
2525

@@ -44,15 +44,16 @@ cls.ResourceDetailBase = function()
4444
if ((c == CR ) || (c == LF))
4545
{
4646
this._line_count++;
47-
if (this._line_count == this._line)
47+
if (this._line_count == this._target_line)
4848
{
4949
var target_pos = child.splitText(pos);
5050
child.parentNode.insertBefore(this._span, target_pos);
5151
this._tops.push(this._span.getBoundingClientRect().top);
5252
child.parentNode.removeChild(this._span);
53+
child.parentNode.normalize();
5354
if (this._tops.length < 2)
5455
{
55-
this._line+=2;
56+
this._target_line+=1;
5657
}
5758
else
5859
{
@@ -72,8 +73,6 @@ cls.ResourceDetailBase = function()
7273
scroll_position-=64;
7374
}
7475
this._root_ele.scrollTop = scroll_position;
75-
76-
child.parentNode.normalize();
7776
this._line_found = true;
7877
return;
7978
}
@@ -94,7 +93,7 @@ cls.ResourceDetailBase = function()
9493
// reset all properties
9594
this._line_count = 0;
9695
this._line_found = false;
97-
this._line = 0;
96+
this._target_line = 0;
9897
this._tops = [];
9998
var _ele = container.querySelectorAll('.'+HIGHLIGHTED_LINE_CLASSNAME)[0];
10099
if (_ele)
@@ -111,7 +110,7 @@ cls.ResourceDetailBase = function()
111110
if (this._root_ele)
112111
{
113112
this.clear_line_numbers(this._root_ele)
114-
this._line = parseInt(data.lines[0]);
113+
this._target_line = parseInt(data.lines[0]);
115114
this._traverse_ele(this._root_ele);
116115
}
117116

0 commit comments

Comments
 (0)