Merge branch 'gr/cvsimport-alternative-cvspass-location' into maint
[git/mingw.git] / gitweb / static / gitweb.js
blob40ec08440b047718bece8efa469683e4b768b68d
1 // Copyright (C) 2007, Fredrik Kuivinen <frekui@gmail.com>
2 // 2007, Petr Baudis <pasky@suse.cz>
3 // 2008-2009, Jakub Narebski <jnareb@gmail.com>
5 /**
6 * @fileOverview JavaScript code for gitweb (git web interface).
7 * @license GPLv2 or later
8 */
10 /* ============================================================ */
11 /* functions for generic gitweb actions and views */
13 /**
14 * used to check if link has 'js' query parameter already (at end),
15 * and other reasons to not add 'js=1' param at the end of link
16 * @constant
18 var jsExceptionsRe = /[;?]js=[01]$/;
20 /**
21 * Add '?js=1' or ';js=1' to the end of every link in the document
22 * that doesn't have 'js' query parameter set already.
24 * Links with 'js=1' lead to JavaScript version of given action, if it
25 * exists (currently there is only 'blame_incremental' for 'blame')
27 * @globals jsExceptionsRe
29 function fixLinks() {
30 var allLinks = document.getElementsByTagName("a") || document.links;
31 for (var i = 0, len = allLinks.length; i < len; i++) {
32 var link = allLinks[i];
33 if (!jsExceptionsRe.test(link)) { // =~ /[;?]js=[01]$/;
34 link.href +=
35 (link.href.indexOf('?') === -1 ? '?' : ';') + 'js=1';
41 /* ============================================================ */
44 * This code uses DOM methods instead of (nonstandard) innerHTML
45 * to modify page.
47 * innerHTML is non-standard IE extension, though supported by most
48 * browsers; however Firefox up to version 1.5 didn't implement it in
49 * a strict mode (application/xml+xhtml mimetype).
51 * Also my simple benchmarks show that using elem.firstChild.data =
52 * 'content' is slightly faster than elem.innerHTML = 'content'. It
53 * is however more fragile (text element fragment must exists), and
54 * less feature-rich (we cannot add HTML).
56 * Note that DOM 2 HTML is preferred over generic DOM 2 Core; the
57 * equivalent using DOM 2 Core is usually shown in comments.
61 /* ============================================================ */
62 /* generic utility functions */
65 /**
66 * pad number N with nonbreakable spaces on the left, to WIDTH characters
67 * example: padLeftStr(12, 3, '\u00A0') == '\u00A012'
68 * ('\u00A0' is nonbreakable space)
70 * @param {Number|String} input: number to pad
71 * @param {Number} width: visible width of output
72 * @param {String} str: string to prefix to string, e.g. '\u00A0'
73 * @returns {String} INPUT prefixed with (WIDTH - INPUT.length) x STR
75 function padLeftStr(input, width, str) {
76 var prefix = '';
78 width -= input.toString().length;
79 while (width > 0) {
80 prefix += str;
81 width--;
83 return prefix + input;
86 /**
87 * Pad INPUT on the left to SIZE width, using given padding character CH,
88 * for example padLeft('a', 3, '_') is '__a'.
90 * @param {String} input: input value converted to string.
91 * @param {Number} width: desired length of output.
92 * @param {String} ch: single character to prefix to string.
94 * @returns {String} Modified string, at least SIZE length.
96 function padLeft(input, width, ch) {
97 var s = input + "";
98 while (s.length < width) {
99 s = ch + s;
101 return s;
105 * Create XMLHttpRequest object in cross-browser way
106 * @returns XMLHttpRequest object, or null
108 function createRequestObject() {
109 try {
110 return new XMLHttpRequest();
111 } catch (e) {}
112 try {
113 return window.createRequest();
114 } catch (e) {}
115 try {
116 return new ActiveXObject("Msxml2.XMLHTTP");
117 } catch (e) {}
118 try {
119 return new ActiveXObject("Microsoft.XMLHTTP");
120 } catch (e) {}
122 return null;
126 /* ============================================================ */
127 /* utility/helper functions (and variables) */
129 var xhr; // XMLHttpRequest object
130 var projectUrl; // partial query + separator ('?' or ';')
132 // 'commits' is an associative map. It maps SHA1s to Commit objects.
133 var commits = {};
136 * constructor for Commit objects, used in 'blame'
137 * @class Represents a blamed commit
138 * @param {String} sha1: SHA-1 identifier of a commit
140 function Commit(sha1) {
141 if (this instanceof Commit) {
142 this.sha1 = sha1;
143 this.nprevious = 0; /* number of 'previous', effective parents */
144 } else {
145 return new Commit(sha1);
149 /* ............................................................ */
150 /* progress info, timing, error reporting */
152 var blamedLines = 0;
153 var totalLines = '???';
154 var div_progress_bar;
155 var div_progress_info;
158 * Detects how many lines does a blamed file have,
159 * This information is used in progress info
161 * @returns {Number|String} Number of lines in file, or string '...'
163 function countLines() {
164 var table =
165 document.getElementById('blame_table') ||
166 document.getElementsByTagName('table')[0];
168 if (table) {
169 return table.getElementsByTagName('tr').length - 1; // for header
170 } else {
171 return '...';
176 * update progress info and length (width) of progress bar
178 * @globals div_progress_info, div_progress_bar, blamedLines, totalLines
180 function updateProgressInfo() {
181 if (!div_progress_info) {
182 div_progress_info = document.getElementById('progress_info');
184 if (!div_progress_bar) {
185 div_progress_bar = document.getElementById('progress_bar');
187 if (!div_progress_info && !div_progress_bar) {
188 return;
191 var percentage = Math.floor(100.0*blamedLines/totalLines);
193 if (div_progress_info) {
194 div_progress_info.firstChild.data = blamedLines + ' / ' + totalLines +
195 ' (' + padLeftStr(percentage, 3, '\u00A0') + '%)';
198 if (div_progress_bar) {
199 //div_progress_bar.setAttribute('style', 'width: '+percentage+'%;');
200 div_progress_bar.style.width = percentage + '%';
205 var t_interval_server = '';
206 var cmds_server = '';
207 var t0 = new Date();
210 * write how much it took to generate data, and to run script
212 * @globals t0, t_interval_server, cmds_server
214 function writeTimeInterval() {
215 var info_time = document.getElementById('generating_time');
216 if (!info_time || !t_interval_server) {
217 return;
219 var t1 = new Date();
220 info_time.firstChild.data += ' + (' +
221 t_interval_server + ' sec server blame_data / ' +
222 (t1.getTime() - t0.getTime())/1000 + ' sec client JavaScript)';
224 var info_cmds = document.getElementById('generating_cmd');
225 if (!info_time || !cmds_server) {
226 return;
228 info_cmds.firstChild.data += ' + ' + cmds_server;
232 * show an error message alert to user within page (in prohress info area)
233 * @param {String} str: plain text error message (no HTML)
235 * @globals div_progress_info
237 function errorInfo(str) {
238 if (!div_progress_info) {
239 div_progress_info = document.getElementById('progress_info');
241 if (div_progress_info) {
242 div_progress_info.className = 'error';
243 div_progress_info.firstChild.data = str;
247 /* ............................................................ */
248 /* coloring rows during blame_data (git blame --incremental) run */
251 * used to extract N from 'colorN', where N is a number,
252 * @constant
254 var colorRe = /\bcolor([0-9]*)\b/;
257 * return N if <tr class="colorN">, otherwise return null
258 * (some browsers require CSS class names to begin with letter)
260 * @param {HTMLElement} tr: table row element to check
261 * @param {String} tr.className: 'class' attribute of tr element
262 * @returns {Number|null} N if tr.className == 'colorN', otherwise null
264 * @globals colorRe
266 function getColorNo(tr) {
267 if (!tr) {
268 return null;
270 var className = tr.className;
271 if (className) {
272 var match = colorRe.exec(className);
273 if (match) {
274 return parseInt(match[1], 10);
277 return null;
280 var colorsFreq = [0, 0, 0];
282 * return one of given possible colors (curently least used one)
283 * example: chooseColorNoFrom(2, 3) returns 2 or 3
285 * @param {Number[]} arguments: one or more numbers
286 * assumes that 1 <= arguments[i] <= colorsFreq.length
287 * @returns {Number} Least used color number from arguments
288 * @globals colorsFreq
290 function chooseColorNoFrom() {
291 // choose the color which is least used
292 var colorNo = arguments[0];
293 for (var i = 1; i < arguments.length; i++) {
294 if (colorsFreq[arguments[i]-1] < colorsFreq[colorNo-1]) {
295 colorNo = arguments[i];
298 colorsFreq[colorNo-1]++;
299 return colorNo;
303 * given two neigbour <tr> elements, find color which would be different
304 * from color of both of neighbours; used to 3-color blame table
306 * @param {HTMLElement} tr_prev
307 * @param {HTMLElement} tr_next
308 * @returns {Number} color number N such that
309 * colorN != tr_prev.className && colorN != tr_next.className
311 function findColorNo(tr_prev, tr_next) {
312 var color_prev = getColorNo(tr_prev);
313 var color_next = getColorNo(tr_next);
316 // neither of neighbours has color set
317 // THEN we can use any of 3 possible colors
318 if (!color_prev && !color_next) {
319 return chooseColorNoFrom(1,2,3);
322 // either both neighbours have the same color,
323 // or only one of neighbours have color set
324 // THEN we can use any color except given
325 var color;
326 if (color_prev === color_next) {
327 color = color_prev; // = color_next;
328 } else if (!color_prev) {
329 color = color_next;
330 } else if (!color_next) {
331 color = color_prev;
333 if (color) {
334 return chooseColorNoFrom((color % 3) + 1, ((color+1) % 3) + 1);
337 // neighbours have different colors
338 // THEN there is only one color left
339 return (3 - ((color_prev + color_next) % 3));
342 /* ............................................................ */
343 /* coloring rows like 'blame' after 'blame_data' finishes */
346 * returns true if given row element (tr) is first in commit group
347 * to be used only after 'blame_data' finishes (after processing)
349 * @param {HTMLElement} tr: table row
350 * @returns {Boolean} true if TR is first in commit group
352 function isStartOfGroup(tr) {
353 return tr.firstChild.className === 'sha1';
357 * change colors to use zebra coloring (2 colors) instead of 3 colors
358 * concatenate neighbour commit groups belonging to the same commit
360 * @globals colorRe
362 function fixColorsAndGroups() {
363 var colorClasses = ['light', 'dark'];
364 var linenum = 1;
365 var tr, prev_group;
366 var colorClass = 0;
367 var table =
368 document.getElementById('blame_table') ||
369 document.getElementsByTagName('table')[0];
371 while ((tr = document.getElementById('l'+linenum))) {
372 // index origin is 0, which is table header; start from 1
373 //while ((tr = table.rows[linenum])) { // <- it is slower
374 if (isStartOfGroup(tr, linenum, document)) {
375 if (prev_group &&
376 prev_group.firstChild.firstChild.href ===
377 tr.firstChild.firstChild.href) {
378 // we have to concatenate groups
379 var prev_rows = prev_group.firstChild.rowSpan || 1;
380 var curr_rows = tr.firstChild.rowSpan || 1;
381 prev_group.firstChild.rowSpan = prev_rows + curr_rows;
382 //tr.removeChild(tr.firstChild);
383 tr.deleteCell(0); // DOM2 HTML way
384 } else {
385 colorClass = (colorClass + 1) % 2;
386 prev_group = tr;
389 var tr_class = tr.className;
390 tr.className = tr_class.replace(colorRe, colorClasses[colorClass]);
391 linenum++;
395 /* ............................................................ */
396 /* time and data */
399 * used to extract hours and minutes from timezone info, e.g '-0900'
400 * @constant
402 var tzRe = /^([+-])([0-9][0-9])([0-9][0-9])$/;
405 * convert numeric timezone +/-ZZZZ to offset from UTC in seconds
407 * @param {String} timezoneInfo: numeric timezone '(+|-)HHMM'
408 * @returns {Number} offset from UTC in seconds for timezone
410 * @globals tzRe
412 function timezoneOffset(timezoneInfo) {
413 var match = tzRe.exec(timezoneInfo);
414 var tz_sign = (match[1] === '-' ? -1 : +1);
415 var tz_hour = parseInt(match[2],10);
416 var tz_min = parseInt(match[3],10);
418 return tz_sign*(((tz_hour*60) + tz_min)*60);
422 * return date in local time formatted in iso-8601 like format
423 * 'yyyy-mm-dd HH:MM:SS +/-ZZZZ' e.g. '2005-08-07 21:49:46 +0200'
425 * @param {Number} epoch: seconds since '00:00:00 1970-01-01 UTC'
426 * @param {String} timezoneInfo: numeric timezone '(+|-)HHMM'
427 * @returns {String} date in local time in iso-8601 like format
429 function formatDateISOLocal(epoch, timezoneInfo) {
430 // date corrected by timezone
431 var localDate = new Date(1000 * (epoch +
432 timezoneOffset(timezoneInfo)));
433 var localDateStr = // e.g. '2005-08-07'
434 localDate.getUTCFullYear() + '-' +
435 padLeft(localDate.getUTCMonth()+1, 2, '0') + '-' +
436 padLeft(localDate.getUTCDate(), 2, '0');
437 var localTimeStr = // e.g. '21:49:46'
438 padLeft(localDate.getUTCHours(), 2, '0') + ':' +
439 padLeft(localDate.getUTCMinutes(), 2, '0') + ':' +
440 padLeft(localDate.getUTCSeconds(), 2, '0');
442 return localDateStr + ' ' + localTimeStr + ' ' + timezoneInfo;
445 /* ............................................................ */
446 /* unquoting/unescaping filenames */
448 /**#@+
449 * @constant
451 var escCodeRe = /\\([^0-7]|[0-7]{1,3})/g;
452 var octEscRe = /^[0-7]{1,3}$/;
453 var maybeQuotedRe = /^\"(.*)\"$/;
454 /**#@-*/
457 * unquote maybe git-quoted filename
458 * e.g. 'aa' -> 'aa', '"a\ta"' -> 'a a'
460 * @param {String} str: git-quoted string
461 * @returns {String} Unquoted and unescaped string
463 * @globals escCodeRe, octEscRe, maybeQuotedRe
465 function unquote(str) {
466 function unq(seq) {
467 var es = {
468 // character escape codes, aka escape sequences (from C)
469 // replacements are to some extent JavaScript specific
470 t: "\t", // tab (HT, TAB)
471 n: "\n", // newline (NL)
472 r: "\r", // return (CR)
473 f: "\f", // form feed (FF)
474 b: "\b", // backspace (BS)
475 a: "\x07", // alarm (bell) (BEL)
476 e: "\x1B", // escape (ESC)
477 v: "\v" // vertical tab (VT)
480 if (seq.search(octEscRe) !== -1) {
481 // octal char sequence
482 return String.fromCharCode(parseInt(seq, 8));
483 } else if (seq in es) {
484 // C escape sequence, aka character escape code
485 return es[seq];
487 // quoted ordinary character
488 return seq;
491 var match = str.match(maybeQuotedRe);
492 if (match) {
493 str = match[1];
494 // perhaps str = eval('"'+str+'"'); would be enough?
495 str = str.replace(escCodeRe,
496 function (substr, p1, offset, s) { return unq(p1); });
498 return str;
501 /* ============================================================ */
502 /* main part: parsing response */
505 * Function called for each blame entry, as soon as it finishes.
506 * It updates page via DOM manipulation, adding sha1 info, etc.
508 * @param {Commit} commit: blamed commit
509 * @param {Object} group: object representing group of lines,
510 * which blame the same commit (blame entry)
512 * @globals blamedLines
514 function handleLine(commit, group) {
516 This is the structure of the HTML fragment we are working
517 with:
519 <tr id="l123" class="">
520 <td class="sha1" title=""><a href=""> </a></td>
521 <td class="linenr"><a class="linenr" href="">123</a></td>
522 <td class="pre"># times (my ext3 doesn&#39;t).</td>
523 </tr>
526 var resline = group.resline;
528 // format date and time string only once per commit
529 if (!commit.info) {
530 /* e.g. 'Kay Sievers, 2005-08-07 21:49:46 +0200' */
531 commit.info = commit.author + ', ' +
532 formatDateISOLocal(commit.authorTime, commit.authorTimezone);
535 // color depends on group of lines, not only on blamed commit
536 var colorNo = findColorNo(
537 document.getElementById('l'+(resline-1)),
538 document.getElementById('l'+(resline+group.numlines))
541 // loop over lines in commit group
542 for (var i = 0; i < group.numlines; i++, resline++) {
543 var tr = document.getElementById('l'+resline);
544 if (!tr) {
545 break;
548 <tr id="l123" class="">
549 <td class="sha1" title=""><a href=""> </a></td>
550 <td class="linenr"><a class="linenr" href="">123</a></td>
551 <td class="pre"># times (my ext3 doesn&#39;t).</td>
552 </tr>
554 var td_sha1 = tr.firstChild;
555 var a_sha1 = td_sha1.firstChild;
556 var a_linenr = td_sha1.nextSibling.firstChild;
558 /* <tr id="l123" class=""> */
559 var tr_class = '';
560 if (colorNo !== null) {
561 tr_class = 'color'+colorNo;
563 if (commit.boundary) {
564 tr_class += ' boundary';
566 if (commit.nprevious === 0) {
567 tr_class += ' no-previous';
568 } else if (commit.nprevious > 1) {
569 tr_class += ' multiple-previous';
571 tr.className = tr_class;
573 /* <td class="sha1" title="?" rowspan="?"><a href="?">?</a></td> */
574 if (i === 0) {
575 td_sha1.title = commit.info;
576 td_sha1.rowSpan = group.numlines;
578 a_sha1.href = projectUrl + 'a=commit;h=' + commit.sha1;
579 if (a_sha1.firstChild) {
580 a_sha1.firstChild.data = commit.sha1.substr(0, 8);
581 } else {
582 a_sha1.appendChild(
583 document.createTextNode(commit.sha1.substr(0, 8)));
585 if (group.numlines >= 2) {
586 var fragment = document.createDocumentFragment();
587 var br = document.createElement("br");
588 var match = commit.author.match(/\b([A-Z])\B/g);
589 if (match) {
590 var text = document.createTextNode(
591 match.join(''));
593 if (br && text) {
594 var elem = fragment || td_sha1;
595 elem.appendChild(br);
596 elem.appendChild(text);
597 if (fragment) {
598 td_sha1.appendChild(fragment);
602 } else {
603 //tr.removeChild(td_sha1); // DOM2 Core way
604 tr.deleteCell(0); // DOM2 HTML way
607 /* <td class="linenr"><a class="linenr" href="?">123</a></td> */
608 var linenr_commit =
609 ('previous' in commit ? commit.previous : commit.sha1);
610 var linenr_filename =
611 ('file_parent' in commit ? commit.file_parent : commit.filename);
612 a_linenr.href = projectUrl + 'a=blame_incremental' +
613 ';hb=' + linenr_commit +
614 ';f=' + encodeURIComponent(linenr_filename) +
615 '#l' + (group.srcline + i);
617 blamedLines++;
619 //updateProgressInfo();
623 // ----------------------------------------------------------------------
625 var inProgress = false; // are we processing response
627 /**#@+
628 * @constant
630 var sha1Re = /^([0-9a-f]{40}) ([0-9]+) ([0-9]+) ([0-9]+)/;
631 var infoRe = /^([a-z-]+) ?(.*)/;
632 var endRe = /^END ?([^ ]*) ?(.*)/;
633 /**@-*/
635 var curCommit = new Commit();
636 var curGroup = {};
638 var pollTimer = null;
641 * Parse output from 'git blame --incremental [...]', received via
642 * XMLHttpRequest from server (blamedataUrl), and call handleLine
643 * (which updates page) as soon as blame entry is completed.
645 * @param {String[]} lines: new complete lines from blamedata server
647 * @globals commits, curCommit, curGroup, t_interval_server, cmds_server
648 * @globals sha1Re, infoRe, endRe
650 function processBlameLines(lines) {
651 var match;
653 for (var i = 0, len = lines.length; i < len; i++) {
655 if ((match = sha1Re.exec(lines[i]))) {
656 var sha1 = match[1];
657 var srcline = parseInt(match[2], 10);
658 var resline = parseInt(match[3], 10);
659 var numlines = parseInt(match[4], 10);
661 var c = commits[sha1];
662 if (!c) {
663 c = new Commit(sha1);
664 commits[sha1] = c;
666 curCommit = c;
668 curGroup.srcline = srcline;
669 curGroup.resline = resline;
670 curGroup.numlines = numlines;
672 } else if ((match = infoRe.exec(lines[i]))) {
673 var info = match[1];
674 var data = match[2];
675 switch (info) {
676 case 'filename':
677 curCommit.filename = unquote(data);
678 // 'filename' information terminates the entry
679 handleLine(curCommit, curGroup);
680 updateProgressInfo();
681 break;
682 case 'author':
683 curCommit.author = data;
684 break;
685 case 'author-time':
686 curCommit.authorTime = parseInt(data, 10);
687 break;
688 case 'author-tz':
689 curCommit.authorTimezone = data;
690 break;
691 case 'previous':
692 curCommit.nprevious++;
693 // store only first 'previous' header
694 if (!'previous' in curCommit) {
695 var parts = data.split(' ', 2);
696 curCommit.previous = parts[0];
697 curCommit.file_parent = unquote(parts[1]);
699 break;
700 case 'boundary':
701 curCommit.boundary = true;
702 break;
703 } // end switch
705 } else if ((match = endRe.exec(lines[i]))) {
706 t_interval_server = match[1];
707 cmds_server = match[2];
709 } else if (lines[i] !== '') {
710 // malformed line
712 } // end if (match)
714 } // end for (lines)
718 * Process new data and return pointer to end of processed part
720 * @param {String} unprocessed: new data (from nextReadPos)
721 * @param {Number} nextReadPos: end of last processed data
722 * @return {Number} end of processed data (new value for nextReadPos)
724 function processData(unprocessed, nextReadPos) {
725 var lastLineEnd = unprocessed.lastIndexOf('\n');
726 if (lastLineEnd !== -1) {
727 var lines = unprocessed.substring(0, lastLineEnd).split('\n');
728 nextReadPos += lastLineEnd + 1 /* 1 == '\n'.length */;
730 processBlameLines(lines);
731 } // end if
733 return nextReadPos;
737 * Handle XMLHttpRequest errors
739 * @param {XMLHttpRequest} xhr: XMLHttpRequest object
741 * @globals pollTimer, commits, inProgress
743 function handleError(xhr) {
744 errorInfo('Server error: ' +
745 xhr.status + ' - ' + (xhr.statusText || 'Error contacting server'));
747 clearInterval(pollTimer);
748 commits = {}; // free memory
750 inProgress = false;
754 * Called after XMLHttpRequest finishes (loads)
756 * @param {XMLHttpRequest} xhr: XMLHttpRequest object (unused)
758 * @globals pollTimer, commits, inProgress
760 function responseLoaded(xhr) {
761 clearInterval(pollTimer);
763 fixColorsAndGroups();
764 writeTimeInterval();
765 commits = {}; // free memory
767 inProgress = false;
771 * handler for XMLHttpRequest onreadystatechange event
772 * @see startBlame
774 * @globals xhr, inProgress
776 function handleResponse() {
779 * xhr.readyState
781 * Value Constant (W3C) Description
782 * -------------------------------------------------------------------
783 * 0 UNSENT open() has not been called yet.
784 * 1 OPENED send() has not been called yet.
785 * 2 HEADERS_RECEIVED send() has been called, and headers
786 * and status are available.
787 * 3 LOADING Downloading; responseText holds partial data.
788 * 4 DONE The operation is complete.
791 if (xhr.readyState !== 4 && xhr.readyState !== 3) {
792 return;
795 // the server returned error
796 // try ... catch block is to work around bug in IE8
797 try {
798 if (xhr.readyState === 3 && xhr.status !== 200) {
799 return;
801 } catch (e) {
802 return;
804 if (xhr.readyState === 4 && xhr.status !== 200) {
805 handleError(xhr);
806 return;
809 // In konqueror xhr.responseText is sometimes null here...
810 if (xhr.responseText === null) {
811 return;
814 // in case we were called before finished processing
815 if (inProgress) {
816 return;
817 } else {
818 inProgress = true;
821 // extract new whole (complete) lines, and process them
822 while (xhr.prevDataLength !== xhr.responseText.length) {
823 if (xhr.readyState === 4 &&
824 xhr.prevDataLength === xhr.responseText.length) {
825 break;
828 xhr.prevDataLength = xhr.responseText.length;
829 var unprocessed = xhr.responseText.substring(xhr.nextReadPos);
830 xhr.nextReadPos = processData(unprocessed, xhr.nextReadPos);
831 } // end while
833 // did we finish work?
834 if (xhr.readyState === 4 &&
835 xhr.prevDataLength === xhr.responseText.length) {
836 responseLoaded(xhr);
839 inProgress = false;
842 // ============================================================
843 // ------------------------------------------------------------
846 * Incrementally update line data in blame_incremental view in gitweb.
848 * @param {String} blamedataUrl: URL to server script generating blame data.
849 * @param {String} bUrl: partial URL to project, used to generate links.
851 * Called from 'blame_incremental' view after loading table with
852 * file contents, a base for blame view.
854 * @globals xhr, t0, projectUrl, div_progress_bar, totalLines, pollTimer
856 function startBlame(blamedataUrl, bUrl) {
858 xhr = createRequestObject();
859 if (!xhr) {
860 errorInfo('ERROR: XMLHttpRequest not supported');
861 return;
864 t0 = new Date();
865 projectUrl = bUrl + (bUrl.indexOf('?') === -1 ? '?' : ';');
866 if ((div_progress_bar = document.getElementById('progress_bar'))) {
867 //div_progress_bar.setAttribute('style', 'width: 100%;');
868 div_progress_bar.style.cssText = 'width: 100%;';
870 totalLines = countLines();
871 updateProgressInfo();
873 /* add extra properties to xhr object to help processing response */
874 xhr.prevDataLength = -1; // used to detect if we have new data
875 xhr.nextReadPos = 0; // where unread part of response starts
877 xhr.onreadystatechange = handleResponse;
878 //xhr.onreadystatechange = function () { handleResponse(xhr); };
880 xhr.open('GET', blamedataUrl);
881 xhr.setRequestHeader('Accept', 'text/plain');
882 xhr.send(null);
884 // not all browsers call onreadystatechange event on each server flush
885 // poll response using timer every second to handle this issue
886 pollTimer = setInterval(xhr.onreadystatechange, 1000);
889 // end of gitweb.js