aboutsummaryrefslogtreecommitdiffstats
path: root/webroot/.static/js/lxrng-funcs.js
blob: 0a06da6bdec91265451a501abcca8101ea85fc18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
function popup_search(searchform) {
	searchform = document.getElementById(searchform);
	searchform.target = 'popup_' + window.name;
	searchform.navtarget.value = window.name;
	window.open('about:blank', 'popup_' + window.name,
		'resizable,width=400,height=600,menubar=yes,status=yes,scrollbars=yes');
	return true;
}

function popup_anchor() {
	var anchor = this;
	window.open('about:blank', 'popup_' + window.name,
		'resizable,width=400,height=600,location=no,menubar=yes,scrollbars=yes'); 

	anchor.target = 'popup_' + window.name;

	if (anchor.href.indexOf("navtarget=") >= 0)
		return true;

	if (anchor.href.indexOf("?") >= 0) {
		anchor.href = anchor.href + ';navtarget=' + window.name;
	}
	else {
		anchor.href = anchor.href + '?navtarget=' + window.name;
	}
	return true;
}

function navigate_here(searchform) {
	searchform = document.getElementById(searchform);
	searchform.target = window.name;
	return true;
}

function window_unique(serial) {
	if (!window.name)
		window.name = 'lxr_source_' + serial;
}

function do_search(form) {
	if (use_ajax_navigation) {
		var res = document.getElementById('search_results');
		res.style.display = 'block';
		res.innerHTML = '<div class="progress">Searching...</div>';
	
		pjx_search(['type__search',
			    'search', 'v', 'tree__' + loaded_tree, 'NO_CACHE'],
			   ['search_results']);
		return false;
	}
	else if (use_popup_navigation) {
		form.target = 'popup_' + window.name;
		form.navtarget.value = window.name;
		reswin = window.open('about:blank', 'popup_' + window.name,
			'resizable,width=400,height=600,location=no,menubar=yes,scrollbars=yes');
	}
	return true;
}

function hide_search() {
	var res = document.getElementById('search_results');
	res.style.display = 'none';
	return false;
}

var loaded_hash;
var loaded_tree;
var loaded_file;
var loaded_ver;
var loaded_line;

var pending_tree;
var pending_file;
var pending_ver;
var pending_line;

function ajax_nav() {
	var file = this.href.replace(/^(http:.*?\/.*?[+][*]\/|)/, '');
	load_file(loaded_tree, file, loaded_ver, '');
	return false;
}

function ajax_jumpto_line() {
	location.hash = location.hash.replace(/\#L\d+$/, '') + 
		this.href.replace(/.*(\#L\d+)$/, '$1');
	check_hash_navigation();	
	return false;
}

function ajax_prefs() {
	if (use_ajax_navigation) {
		var full_path = location.href.match(/(.*?)\/*#/)[1];
		full_path = full_path + '/' + loaded_tree;
		if (loaded_ver) {
			full_path = full_path + '+' + loaded_ver;
		}
		full_path = full_path + '/+prefs?return=' + loaded_file.replace(/^\/?$/, '.');
		location = full_path;
		return false;
	}
	else {
		return true;
	}
}

var hash_check;
function check_hash_navigation() {
	if (location.hash != loaded_hash) {
		if (location.hash.replace(/\#L\d+$/, '') == 
		    loaded_hash.replace(/\#L\d+$/, ''))
		{
			var l = location.hash.replace(/.*#(L\d+)$/, '$1');
			var a = document.getElementById(l);
			if (l && a) {
				a.name = location.hash.replace(/^\#/, '');
				location.hash = a.name;
				loaded_hash = location.hash;
			}
			hash_check = setTimeout('check_hash_navigation()', 50);
		}
		else {
			load_content();		
		}
	}
	else {
		hash_check = setTimeout('check_hash_navigation()', 50);
	}
}

function load_file(tree, file, ver, line) {
	if (!use_ajax_navigation) {
		return true;
	}

	if (hash_check) {
		clearTimeout(hash_check);
	}

	if ((pending_tree == tree) &&
	    (pending_file == file) &&
	    (pending_ver == ver))
	{
	        if (line > 0)
			line = '#L' + line;
		location.hash = location.hash.replace(/\#L\d+$/, '') + line;
		check_hash_navigation();
		return false;
	}


	var res = document.getElementById('content');

	res.innerHTML = '<div class="progress">Loading...</div>';
	pending_line = line;
	pending_tree = tree;
	pending_file = file;
	if (ver) {
		pending_ver = ver;
	}
	else {
		pending_ver = '';
	}
	
	if (!file)
		file = '/';
	if (line < 1)
		line = 1;
	pjx_load_file(['tree__' + tree, 'file__' + file, 'v__' + ver,
		       'line__' + line, 'NO_CACHE'],
		      [load_file_finalize]);
	return false;
}

function load_file_finalize(content) {
	var res = document.getElementById('content');
	res.innerHTML = 'Done';
	res.innerHTML = content;
	var head = document.getElementById('current_path');
	head.innerHTML = '<a class=\"fref\" href=\".\">' + pending_tree + '</a>';
	var path_walked = '';
	var elems = pending_file.split(/\//);
	for (var i=0; i<elems.length; i++) {
		if (elems[i] != '') {
			head.innerHTML = head.innerHTML + '/' +
				'<a class=\"fref\" href=\"' + path_walked + elems[i] +
				'\">' + elems[i] + '</a>';
			path_walked = path_walked + elems[i] + '/';
		}
	}
	document.title = 'LXR ' + pending_tree + '/' + pending_file;

	var full_tree = pending_tree;
	if (pending_ver) {
		full_tree = full_tree + '+' + pending_ver;
	}
	var full_path = full_tree + '/' + pending_file.replace(/^\/?/, '');

	var pre = document.getElementById('file_contents');
	if (pre && pre.className == 'partial') {
		pjx_load_file(['tree__' + pending_tree, 'file__' + pending_file,
			       'v__' + pending_ver, 'full__1', 'NO_CACHE'],
			      [load_file_finalize]);
	}

	var print = document.getElementById('lxr_print');
	var dirlist = document.getElementById('content_dir');
	if (dirlist) {
		print.style.display = 'none';
	}
	else {
		var pform = document.getElementById('print_form');
		pform.action = '../' + full_tree + '/+print=' + 
			pending_file.replace(/^\/?/, '');
		print.style.display = 'inline';
	}

	if (hash_check) {
		clearTimeout(hash_check);
	}
	if (pending_line) {
		var anchor = document.getElementById('L' + pending_line);
		if (anchor) {
			anchor.name = full_path + '#L' + pending_line;
			location.hash = full_path + '#L' + pending_line;
		}
		else {
			location.hash = full_path;
		}
		loaded_line = pending_line;
	}
	else {
		location.hash = full_path;
		loaded_line = 0;
	}
	loaded_hash = location.hash;
	loaded_tree = pending_tree;
	loaded_file = pending_file;
	loaded_ver = pending_ver;
	hash_check = setTimeout('check_hash_navigation()', 50);

//	TODO: This really takes oodles of time.  Consider coding into html.
	var i;
	for (i = 0; i < document.links.length; i++) {
		if (document.links[i].className == 'fref') {
			document.links[i].onclick = ajax_nav;
		}
		else if (document.links[i].className == 'line') {
			document.links[i].onclick = ajax_jumpto_line;
		}
		else if (document.links[i].className == 'sref' || 
		    document.links[i].className == 'falt')
		{
			document.links[i].onclick = ajax_lookup_anchor; 
		}

	}
}

function load_content() {
	if (!use_ajax_navigation) {
		return false;
	}
	var tree = location.hash.split('/', 1);
	tree = tree[0].split(/[+]/);
	var ver = tree[1] || '';
	tree = tree[0].replace(/^#/, '');
	var file = location.hash.replace(/^[^\/]*\/?/, '');
	var line = file.replace(/.*\#L(\d+)/, '$1');
	file = file.replace(/\#L\d+$/, '');
	load_file(tree, file, ver, line);

	pjx_releases(['tree__' + tree, 'NO_CACHE'],
		     [load_content_finalize]);
}

function load_content_finalize(content) {
	var res = document.getElementById('ver_select');
	res.innerHTML = content;
	var verlist = document.getElementById('v');
	verlist.value = pending_ver;
}

function update_version(verlist, base_url, tree, defversion, path) {
	if (use_ajax_navigation) {
		var file = location.hash.replace(/^[^\/]*\//, '');
		var line = file.replace(/.*\#L(\d+)/, '$1');
		file = file.replace(/\#L\d*$/, '');
	
		load_file(loaded_tree, file, verlist.value, line);
		return false;
	}
	else {
		var newurl = base_url.replace(/[^\/]*\/?$/, '');
		if (verlist.value == defversion) {
			newurl = newurl + tree;
		}
		else {
			newurl = newurl + tree + '+' + verlist.value;
		}
		newurl = newurl + '/' + path.replace(/^\//, '');
		document.location = newurl;
	}
}

function next_version() {
	var verlist = document.getElementById('v');
	if (verlist.selectedIndex > 0) {
		verlist.selectedIndex = verlist.selectedIndex - 1;
		update_version(verlist, '', '', '', '');
	}
	return false;
}

function previous_version() {
	var verlist = document.getElementById('v');
	if (verlist.selectedIndex < verlist.length - 1) {
		verlist.selectedIndex = verlist.selectedIndex + 1;
		update_version(verlist, '', '', '', '');
	}
	return false;
}

function popup_prepare(serial) {
	window_unique(serial);
	var i;
	for (i = 0; i < document.links.length; i++) {
		if (document.links[i].className == 'sref' || 
		    document.links[i].className == 'falt')
		{
			document.links[i].onclick = popup_anchor;
		}
	}
}

function ajax_lookup_anchor(event, anchor) {
	if (!use_ajax_navigation)
		return true;

	if (!anchor)
		anchor = this;
	
	lookup = anchor.href.replace(/^(http:.*?\/.*?[+][*]\/|)/, '');

	var lvar = document.getElementById('ajax_lookup');
	lvar.value = lookup;

	var res = document.getElementById('search_results');
	res.style.display = 'block';
	res.innerHTML = '<div class="progress">Searching...</div>';

	pjx_search(['ajax_lookup', 'v', 'tree__' + loaded_tree, 'NO_CACHE'],
		   ['search_results']);
	return false;
}