-
Notifications
You must be signed in to change notification settings - Fork 0
/
filedrag.js
144 lines (130 loc) · 2.9 KB
/
filedrag.js
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
var file;
// getElementById
function $id(id) {
return document.getElementById(id);
}
// file selection
function FileSelectHandler(e) {
// cancel event and hover styling
FileDragHover(e);
// fetch FileList object
var files = e.target.files || e.dataTransfer.files;
file = files[0];
// Build spreadsheet
var data = [];
for (let i=0; i<files.length; i++) {
path = files[i].webkitRelativePath;
if (!path) {
path = files[i].name;
}
let row = [
'', //Thumbnail
path, //File path
'', //Title
'', //Date
'', //Description
'', //Rights
files[i].size + ' bytes', //Extent, Possible TODO: human-friendly extent.
'', //Subjects
'', //Access Terms
'', //Member Of
'', //Node ID
];
data.push(row);
};
loadData(data, [
{
type: 'image',
title: 'Thumbnail',
width: 120
},
{
type: 'text',
title: 'File',
width: 120
},
{
type: 'text',
title: 'Title',
width: 120,
wordWrap: true
},
{
type: 'text',
title: 'Date',
width: 120
},
{
type: 'text',
title: 'Description',
width: 120,
wordWrap: true
},
{
type: 'text',
title: 'Rights',
width: 120,
wordWrap: true
},
{
type: 'text',
title: 'Extent',
width: 100,
wordWrap: true
},
{
type: 'autocomplete',
title: 'Subjects',
width: 200,
multiple: true,
source: subjectsDropdown
},
{
type: 'dropdown',
title: 'Access Terms',
width: 200,
multiple: true,
source: accessDropdown
},
{
type: 'dropdown',
title: 'Member Of',
width: 120,
source: []
},
{
type: 'hidden',
title: 'Node ID'
}
]);
}
// file drag hover
function FileDragHover(e) {
e.stopPropagation();
e.preventDefault();
e.target.className = (e.type == "dragover" ? "hover" : "");
}
// call initialization file
if (window.File && window.FileList && window.FileReader) {
Init();
}
//
// initialize
function Init() {
var fileselect = $id("fileselect"),
filedrag = $id("filedrag"),
submitbutton = $id("submitbutton");
// file select
fileselect.addEventListener("change", FileSelectHandler, false);
// is XHR2 available?
var xhr = new XMLHttpRequest();
if (xhr.upload) {
// file drop
filedrag.addEventListener("dragover", FileDragHover, false);
filedrag.addEventListener("dragleave", FileDragHover, false);
filedrag.addEventListener("drop", FileSelectHandler, false);
filedrag.style.display = "block";
// remove submit button
submitbutton.style.display = "none";
}
}