Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SRCT
photos
Commits
b45112f4
Commit
b45112f4
authored
Jul 26, 2014
by
Tobias Reich
Browse files
Added comments to upload and fixed a bug with unsupported files
parent
2021f850
Changes
2
Expand all
Show whitespace changes
Inline
Side-by-side
assets/js/upload.js
View file @
b45112f4
...
...
@@ -58,18 +58,51 @@ upload = {
var
albumID
=
album
.
getID
(),
process
=
function
(
files
,
file
)
{
var
formData
=
new
FormData
(),
xhr
=
new
XMLHttpRequest
(),
pre_progress
=
0
,
progress
,
finish
=
function
()
{
window
.
onbeforeunload
=
null
;
$
(
"
#upload_files
"
).
val
(
""
);
upload
.
close
();
if
(
album
.
getID
()
===
false
)
lychee
.
goto
(
"
0
"
);
else
album
.
load
(
albumID
);
};
// Check if file is supported
if
(
file
.
supported
===
false
)
{
// Skip file
if
(
file
.
next
!==
null
)
process
(
files
,
file
.
next
);
return
false
;
else
{
// Look for supported files
// If zero files are supported, hide the upload after a delay
var
hasSupportedFiles
=
false
;
for
(
var
i
=
0
;
i
<
files
.
length
;
i
++
)
{
if
(
files
[
i
].
supported
===
true
)
{
hasSupportedFiles
=
true
;
break
;
}
var
formData
=
new
FormData
(),
xhr
=
new
XMLHttpRequest
(),
pre_progress
=
0
,
progress
;
}
if
(
hasSupportedFiles
===
false
)
setTimeout
(
finish
,
2000
);
}
return
false
;
}
formData
.
append
(
"
function
"
,
"
upload
"
);
formData
.
append
(
"
albumID
"
,
albumID
);
...
...
@@ -79,10 +112,12 @@ upload = {
xhr
.
onload
=
function
()
{
var
wait
;
// On success
if
(
xhr
.
status
===
200
)
{
var
wait
;
// Set status to finished
$
(
"
.upload_message .rows .row:nth-child(
"
+
(
file
.
num
+
1
)
+
"
) .status
"
)
.
html
(
"
Finished
"
)
.
addClass
(
"
success
"
);
...
...
@@ -90,6 +125,7 @@ upload = {
file
.
ready
=
true
;
wait
=
false
;
// Check if there are file which are not finished
for
(
var
i
=
0
;
i
<
files
.
length
;
i
++
)
{
if
(
files
[
i
].
ready
===
false
)
{
...
...
@@ -99,18 +135,8 @@ upload = {
}
if
(
wait
===
false
)
{
window
.
onbeforeunload
=
null
;
$
(
"
#upload_files
"
).
val
(
""
);
upload
.
close
();
if
(
album
.
getID
()
===
false
)
lychee
.
goto
(
"
0
"
);
else
album
.
load
(
albumID
);
}
// Finish upload when all files are finished
if
(
wait
===
false
)
finish
();
}
...
...
@@ -120,8 +146,10 @@ upload = {
if
(
e
.
lengthComputable
)
{
// Calculate progress
progress
=
(
e
.
loaded
/
e
.
total
*
100
|
0
);
// Set progress when progress has changed
if
(
progress
>
pre_progress
)
{
$
(
"
.upload_message .rows .row:nth-child(
"
+
(
file
.
num
+
1
)
+
"
) .status
"
).
html
(
progress
+
"
%
"
);
pre_progress
=
progress
;
...
...
@@ -129,12 +157,15 @@ upload = {
if
(
progress
>=
100
)
{
// Scroll to the uploading file
var
scrollPos
=
0
;
if
((
file
.
num
+
1
)
>
4
)
scrollPos
=
(
file
.
num
+
1
-
4
)
*
40
$
(
"
.upload_message .rows
"
).
scrollTop
(
scrollPos
);
// Set status to processing
$
(
"
.upload_message .rows .row:nth-child(
"
+
(
file
.
num
+
1
)
+
"
) .status
"
).
html
(
"
Processing
"
);
// Upload next file
if
(
file
.
next
!==
null
)
process
(
files
,
file
.
next
);
}
...
...
@@ -159,6 +190,7 @@ upload = {
if
(
i
<
files
.
length
-
1
)
files
[
i
].
next
=
files
[
i
+
1
];
else
files
[
i
].
next
=
null
;
// Check if file is supported
if
(
files
[
i
].
type
!==
"
image/jpeg
"
&&
files
[
i
].
type
!==
"
image/jpg
"
&&
files
[
i
].
type
!==
"
image/png
"
&&
files
[
i
].
type
!==
"
image/gif
"
)
{
files
[
i
].
ready
=
true
;
...
...
@@ -172,6 +204,7 @@ upload = {
upload
.
show
(
"
Uploading
"
,
files
);
// Upload first file
process
(
files
,
files
[
0
]);
},
...
...
assets/min/main.js
View file @
b45112f4
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment