Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
85e73175
Commit
85e73175
authored
Jul 18, 2017
by
Brandon Everett
Committed by
Clement Ho
Jul 18, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor variables initialization in dropzone_input.js
parent
901319fc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
47 deletions
+58
-47
app/assets/javascripts/dropzone_input.js
app/assets/javascripts/dropzone_input.js
+54
-47
changelogs/unreleased/29901-refactor-initialization-dropzone_input-js.yml
...eased/29901-refactor-initialization-dropzone_input-js.yml
+4
-0
No files found.
app/assets/javascripts/dropzone_input.js
View file @
85e73175
...
...
@@ -5,21 +5,28 @@ import './preview_markdown';
window
.
DropzoneInput
=
(
function
()
{
function
DropzoneInput
(
form
)
{
var
updateAttachingMessage
,
$attachingFileMessage
,
$mdArea
,
$attachButton
,
$cancelButton
,
$retryLink
,
$uploadingErrorContainer
,
$uploadingErrorMessage
,
$uploadProgress
,
$uploadingProgressContainer
,
appendToTextArea
,
btnAlert
,
child
,
closeAlertMessage
,
closeSpinner
,
divHover
,
divSpinner
,
dropzone
,
$formDropzone
,
formTextarea
,
getFilename
,
handlePaste
,
iconPaperclip
,
iconSpinner
,
insertToTextArea
,
isImage
,
maxFileSize
,
pasteText
,
uploadsPath
,
showError
,
showSpinner
,
uploadFile
,
addFileToForm
;
Dropzone
.
autoDiscover
=
false
;
divHover
=
'
<div class="div-dropzone-hover"></div>
'
;
iconPaperclip
=
'
<i class="fa fa-paperclip div-dropzone-icon"></i>
'
;
$attachButton
=
form
.
find
(
'
.button-attach-file
'
);
$attachingFileMessage
=
form
.
find
(
'
.attaching-file-message
'
);
$cancelButton
=
form
.
find
(
'
.button-cancel-uploading-files
'
);
$retryLink
=
form
.
find
(
'
.retry-uploading-link
'
);
$uploadProgress
=
form
.
find
(
'
.uploading-progress
'
);
$uploadingErrorContainer
=
form
.
find
(
'
.uploading-error-container
'
);
$uploadingErrorMessage
=
form
.
find
(
'
.uploading-error-message
'
);
$uploadingProgressContainer
=
form
.
find
(
'
.uploading-progress-container
'
);
uploadsPath
=
window
.
uploads_path
||
null
;
maxFileSize
=
gon
.
max_file_size
||
10
;
formTextarea
=
form
.
find
(
'
.js-gfm-input
'
);
const
divHover
=
'
<div class="div-dropzone-hover"></div>
'
;
const
iconPaperclip
=
'
<i class="fa fa-paperclip div-dropzone-icon"></i>
'
;
const
$attachButton
=
form
.
find
(
'
.button-attach-file
'
);
const
$attachingFileMessage
=
form
.
find
(
'
.attaching-file-message
'
);
const
$cancelButton
=
form
.
find
(
'
.button-cancel-uploading-files
'
);
const
$retryLink
=
form
.
find
(
'
.retry-uploading-link
'
);
const
$uploadProgress
=
form
.
find
(
'
.uploading-progress
'
);
const
$uploadingErrorContainer
=
form
.
find
(
'
.uploading-error-container
'
);
const
$uploadingErrorMessage
=
form
.
find
(
'
.uploading-error-message
'
);
const
$uploadingProgressContainer
=
form
.
find
(
'
.uploading-progress-container
'
);
const
uploadsPath
=
window
.
uploads_path
||
null
;
const
maxFileSize
=
gon
.
max_file_size
||
10
;
const
formTextarea
=
form
.
find
(
'
.js-gfm-input
'
);
let
handlePaste
;
let
pasteText
;
let
addFileToForm
;
let
updateAttachingMessage
;
let
isImage
;
let
getFilename
;
let
uploadFile
;
formTextarea
.
wrap
(
'
<div class="div-dropzone"></div>
'
);
formTextarea
.
on
(
'
paste
'
,
(
function
(
_this
)
{
return
function
(
event
)
{
...
...
@@ -28,16 +35,16 @@ window.DropzoneInput = (function() {
})(
this
));
// Add dropzone area to the form.
$mdArea
=
formTextarea
.
closest
(
'
.md-area
'
);
const
$mdArea
=
formTextarea
.
closest
(
'
.md-area
'
);
form
.
setupMarkdownPreview
();
$formDropzone
=
form
.
find
(
'
.div-dropzone
'
);
const
$formDropzone
=
form
.
find
(
'
.div-dropzone
'
);
$formDropzone
.
parent
().
addClass
(
'
div-dropzone-wrapper
'
);
$formDropzone
.
append
(
divHover
);
$formDropzone
.
find
(
'
.div-dropzone-hover
'
).
append
(
iconPaperclip
);
if
(
!
uploadsPath
)
return
;
dropzone
=
$formDropzone
.
dropzone
({
const
dropzone
=
$formDropzone
.
dropzone
({
url
:
uploadsPath
,
dictDefaultMessage
:
''
,
clickable
:
true
,
...
...
@@ -117,7 +124,7 @@ window.DropzoneInput = (function() {
}
});
child
=
$
(
dropzone
[
0
]).
children
(
'
textarea
'
);
c
onst
c
hild
=
$
(
dropzone
[
0
]).
children
(
'
textarea
'
);
// removeAllFiles(true) stops uploading files (if any)
// and remove them from dropzone files queue.
...
...
@@ -214,6 +221,35 @@ window.DropzoneInput = (function() {
return
value
.
first
();
};
const
showSpinner
=
function
(
e
)
{
return
$uploadingProgressContainer
.
removeClass
(
'
hide
'
);
};
const
closeSpinner
=
function
()
{
return
$uploadingProgressContainer
.
addClass
(
'
hide
'
);
};
const
showError
=
function
(
message
)
{
$uploadingErrorContainer
.
removeClass
(
'
hide
'
);
$uploadingErrorMessage
.
html
(
message
);
};
const
closeAlertMessage
=
function
()
{
return
form
.
find
(
'
.div-dropzone-alert
'
).
alert
(
'
close
'
);
};
const
insertToTextArea
=
function
(
filename
,
url
)
{
return
$
(
child
).
val
(
function
(
index
,
val
)
{
return
val
.
replace
(
`{{
${
filename
}
}}`
,
url
);
});
};
const
appendToTextArea
=
function
(
url
)
{
return
$
(
child
).
val
(
function
(
index
,
val
)
{
return
val
+
url
+
"
\n
"
;
});
};
uploadFile
=
function
(
item
,
filename
)
{
var
formData
;
formData
=
new
FormData
();
...
...
@@ -262,35 +298,6 @@ window.DropzoneInput = (function() {
messageContainer
.
text
(
attachingMessage
);
};
insertToTextArea
=
function
(
filename
,
url
)
{
return
$
(
child
).
val
(
function
(
index
,
val
)
{
return
val
.
replace
(
`{{
${
filename
}
}}`
,
url
);
});
};
appendToTextArea
=
function
(
url
)
{
return
$
(
child
).
val
(
function
(
index
,
val
)
{
return
val
+
url
+
"
\n
"
;
});
};
showSpinner
=
function
(
e
)
{
return
$uploadingProgressContainer
.
removeClass
(
'
hide
'
);
};
closeSpinner
=
function
()
{
return
$uploadingProgressContainer
.
addClass
(
'
hide
'
);
};
showError
=
function
(
message
)
{
$uploadingErrorContainer
.
removeClass
(
'
hide
'
);
$uploadingErrorMessage
.
html
(
message
);
};
closeAlertMessage
=
function
()
{
return
form
.
find
(
'
.div-dropzone-alert
'
).
alert
(
'
close
'
);
};
form
.
find
(
'
.markdown-selector
'
).
click
(
function
(
e
)
{
e
.
preventDefault
();
$
(
this
).
closest
(
'
.gfm-form
'
).
find
(
'
.div-dropzone
'
).
click
();
...
...
changelogs/unreleased/29901-refactor-initialization-dropzone_input-js.yml
0 → 100644
View file @
85e73175
---
title
:
refactor initializations in dropzone_input.js
merge_request
:
12768
author
:
Brandon Everett
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