Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Donald Haase
Web-Comic-Reader
Commits
a0fa25b5
Commit
a0fa25b5
authored
Oct 22, 2019
by
Afif Zafri
Browse files
implement setTimeout to reduce browser crash
parent
a0a59992
Changes
1
Hide whitespace changes
Inline
Side-by-side
assets/js/script.js
View file @
a0fa25b5
...
...
@@ -47,12 +47,6 @@ $(document).ready(function(){
{
$
(
'
#output
'
).
append
(
"
<b>
"
+
archive
.
file_name
+
"
</b><br><i>Click on the image to enlarge</i><br><br>
"
);
readContents
(
archive
);
// hide loading
$
(
'
.se-pre-con
'
).
fadeOut
(
'
slow
'
);
// show output box
$
(
'
#output
'
).
fadeIn
(
'
slow
'
);
}
else
{
...
...
@@ -74,16 +68,26 @@ $(document).ready(function(){
// iterate through all the contents
for
(
var
i
=
0
;
i
<
entries
.
length
;
i
++
)
{
filename
=
entries
[
i
].
name
;
// check, only output file, not folder
if
(
getExt
(
filename
)
!=
''
)
{
// call function to create blob and url. allow us to read/view the contents
createBlobs
(
entries
[
i
]);
}
{
processEntries
(
entries
,
i
,
entries
.
length
);
}
}
// implement setTimout()
// This can minimize browser from overprocessing which can caused browser to be not responding
// simple way to mimics multi threading
function
processEntries
(
entries
,
i
,
max
)
{
setTimeout
(
function
()
{
filename
=
entries
[
i
].
name
;
// check, only output file, not folder
if
(
getExt
(
filename
)
!=
''
)
{
// call function to create blob and url. allow us to read/view the contents
createBlobs
(
entries
[
i
],
i
,
max
);
}
},
i
*
700
);
}
// function to return file extension based on file name
function
getExt
(
filename
)
...
...
@@ -122,7 +126,7 @@ $(document).ready(function(){
}
// function to convert the archive contents into blobs, and return URL
function
createBlobs
(
entry
)
function
createBlobs
(
entry
,
i
,
max
)
{
entry
.
readData
(
function
(
data
,
err
)
{
// Convert the data into an Object URL
...
...
@@ -131,8 +135,16 @@ $(document).ready(function(){
// output the images
$
(
'
#output
'
).
append
(
"
<a href='
"
+
url
+
"
' id='comicImg'><img src='
"
+
url
+
"
' class='imgUrl'/></a>
"
);
});
// only hide loading spinnder when done process all
if
(
i
==
(
max
-
1
))
{
// hide loading
$
(
'
.se-pre-con
'
).
fadeOut
(
'
slow
'
);
// show output box
$
(
'
#output
'
).
fadeIn
(
'
slow
'
);
}
});
}
// function to clear all previous blobs, free up memory
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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