1
1
// Copyright (C) 2007, Fredrik Kuivinen <[email protected] >
2
2
// 2007, Petr Baudis <[email protected] >
3
- // 2008-2009 , Jakub Narebski <[email protected] >
3
+ // 2008-2011 , Jakub Narebski <[email protected] >
4
4
5
5
/**
6
- * @fileOverview JavaScript code for gitweb (git web interface).
6
+ * @fileOverview JavaScript side of Ajax-y 'blame_incremental' view in gitweb
7
7
* @license GPLv2 or later
8
8
*/
9
9
10
- /* ============================================================ */
11
- /* functions for generic gitweb actions and views */
12
-
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
17
- */
18
- var jsExceptionsRe = / [ ; ? ] j s = [ 0 1 ] $ / ;
19
-
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.
23
- *
24
- * Links with 'js=1' lead to JavaScript version of given action, if it
25
- * exists (currently there is only 'blame_incremental' for 'blame')
26
- *
27
- * @globals jsExceptionsRe
28
- */
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' ;
36
- }
37
- }
38
- }
39
-
40
-
41
- /* ============================================================ */
42
10
43
11
/*
44
12
* This code uses DOM methods instead of (nonstandard) innerHTML
@@ -58,71 +26,6 @@ function fixLinks() {
58
26
*/
59
27
60
28
61
- /* ============================================================ */
62
- /* generic utility functions */
63
-
64
-
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)
69
- *
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
74
- */
75
- function padLeftStr ( input , width , str ) {
76
- var prefix = '' ;
77
-
78
- width -= input . toString ( ) . length ;
79
- while ( width > 0 ) {
80
- prefix += str ;
81
- width -- ;
82
- }
83
- return prefix + input ;
84
- }
85
-
86
- /**
87
- * Pad INPUT on the left to SIZE width, using given padding character CH,
88
- * for example padLeft('a', 3, '_') is '__a'.
89
- *
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.
93
- *
94
- * @returns {String } Modified string, at least SIZE length.
95
- */
96
- function padLeft ( input , width , ch ) {
97
- var s = input + "" ;
98
- while ( s . length < width ) {
99
- s = ch + s ;
100
- }
101
- return s ;
102
- }
103
-
104
- /**
105
- * Create XMLHttpRequest object in cross-browser way
106
- * @returns XMLHttpRequest object, or null
107
- */
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 ) { }
121
-
122
- return null ;
123
- }
124
-
125
-
126
29
/* ============================================================ */
127
30
/* utility/helper functions (and variables) */
128
31
@@ -392,111 +295,6 @@ function fixColorsAndGroups() {
392
295
}
393
296
}
394
297
395
- /* ............................................................ */
396
- /* time and data */
397
-
398
- /**
399
- * used to extract hours and minutes from timezone info, e.g '-0900'
400
- * @constant
401
- */
402
- var tzRe = / ^ ( [ + - ] ) ( [ 0 - 9 ] [ 0 - 9 ] ) ( [ 0 - 9 ] [ 0 - 9 ] ) $ / ;
403
-
404
- /**
405
- * convert numeric timezone +/-ZZZZ to offset from UTC in seconds
406
- *
407
- * @param {String } timezoneInfo: numeric timezone '(+|-)HHMM'
408
- * @returns {Number } offset from UTC in seconds for timezone
409
- *
410
- * @globals tzRe
411
- */
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 ) ;
417
-
418
- return tz_sign * ( ( ( tz_hour * 60 ) + tz_min ) * 60 ) ;
419
- }
420
-
421
- /**
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'
424
- *
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
428
- */
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' ) ;
441
-
442
- return localDateStr + ' ' + localTimeStr + ' ' + timezoneInfo ;
443
- }
444
-
445
- /* ............................................................ */
446
- /* unquoting/unescaping filenames */
447
-
448
- /**#@+
449
- * @constant
450
- */
451
- var escCodeRe = / \\ ( [ ^ 0 - 7 ] | [ 0 - 7 ] { 1 , 3 } ) / g;
452
- var octEscRe = / ^ [ 0 - 7 ] { 1 , 3 } $ / ;
453
- var maybeQuotedRe = / ^ \" ( .* ) \" $ / ;
454
- /**#@-*/
455
-
456
- /**
457
- * unquote maybe git-quoted filename
458
- * e.g. 'aa' -> 'aa', '"a\ta"' -> 'a a'
459
- *
460
- * @param {String } str: git-quoted string
461
- * @returns {String } Unquoted and unescaped string
462
- *
463
- * @globals escCodeRe, octEscRe, maybeQuotedRe
464
- */
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)
478
- } ;
479
-
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 ] ;
486
- }
487
- // quoted ordinary character
488
- return seq ;
489
- }
490
-
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 ) ; } ) ;
497
- }
498
- return str ;
499
- }
500
298
501
299
/* ============================================================ */
502
300
/* main part: parsing response */
@@ -886,4 +684,4 @@ function startBlame(blamedataUrl, bUrl) {
886
684
pollTimer = setInterval ( xhr . onreadystatechange , 1000 ) ;
887
685
}
888
686
889
- // end of gitweb .js
687
+ /* end of blame_incremental .js */
0 commit comments