Welcome to mirror list, hosted at ThFree Co, Russian Federation.

script.js « .autoindex - github.com/iglvzx/IGalvez.Autoindex.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0c61913d7543fafa5d6d99f35a6fa4405afa7438 (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
document.title = decodeURI(document.URL); // set page title to full URL

$('table').addClass('table'); // add Bootstrap CSS to table

$('td').removeAttr('align'); // remove align="right" from cells

$('td').each(function() { // change text for no size value
	if(this.innerHTML == '  - ') {
		this.innerHTML = '';
	}
});

// move header row to thead ------------------------------------------------------------------------
var header = $('table tbody tr').first();

var thead = $('<thead/>');
thead.append(header);
$('table').prepend(thead);

// CSS and icons for header links ------------------------------------------------------------------
var hName = $('a', header).eq(0);
var hModified = $('a', header).eq(1);
var hSize = $('a', header).eq(2);

if(/\/$/.test(document.URL)) {
	addIcon(hName, 'chevron-down', 'right');
} else {
	if(/\?C=N;O=D$/.test(document.URL)){
		addIcon(hName, 'chevron-up', 'right');
	} else if(/\?C=N;O=A$/.test(document.URL)){
		addIcon(hName, 'chevron-down', 'right');
	}

	if(/\?C=M;O=D$/.test(document.URL)){
		addIcon(hModified, 'chevron-up', 'right');
	} else if(/\?C=M;O=A$/.test(document.URL)){
		addIcon(hModified, 'chevron-down', 'right');
	}

	if(/\?C=S;O=D$/.test(document.URL)){
		addIcon(hSize, 'chevron-up', 'right');
	} else if(/\?C=S;O=A$/.test(document.URL)){
		addIcon(hSize, 'chevron-down', 'right');
	}
}

function addIcon(object, icon, className) {
	var HTML = '<i class="' + className + ' fa fa-fw fa-' + icon + '"></i>';

	if(className == 'right') {
		object.append(HTML);
	} else if(className == 'left') {
		object.prepend(HTML);
	}
}

// CSS and icons to rows and links -----------------------------------------------------------------
$('table tbody tr').each(function(i, obj) {

	var link = $('a', this).first();
	link.parent().addClass('td-link');
	var file = link.text();

	if(file == 'Parent Directory' && i == 0){ // parent directory
		link.attr('data-type', 'parent');
		link.attr('id', 'parent');
		$(this).addClass('warning');
		link.text('../');
		addIcon(link, 'folder', 'left');

	} else {

		if (file.substring(file.length - 1) == '/') {
			link.attr('data-type', 'folder');
			$(this).addClass('active');
			addIcon(link, 'folder', 'left');
		} else {

			var fparts = file.split('.');

			if(fparts.length > 1) {

				var ext = fparts[fparts.length - 1].toLowerCase();

				var extensionFound = false;
				for(var f = 0; f < fileTypes.length; f++) {

					var icon = fileTypes[f].icon;
					var extensions = fileTypes[f].extensions;

					if($.inArray(ext, extensions) > -1) {

						extensionFound = true;
						addIcon(link, icon, 'left');
						break;

					}
				}

				if(!extensionFound) { // extension not found in fileTypes array of objects
					addIcon(link, 'file-o', 'left');
				}

			} else { // files with no extension
				addIcon(link, 'file-o', 'left');
			}

			link.attr('target', '_blank');
			link.attr('data-type', 'file');
		}

	}

});

$('#refresh').click(function(e) {
	e.preventDefault();
	location.reload();
});

var parent = $('#parent');

if(parent.length) {
	$('#nav-buttons').append('<li><a href="' + parent.attr('href') + '"><i class="fa fa-arrow-up"></i>Up</a></li>');
}

$('#wrapper').show();