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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
d7eb6e55
Commit
d7eb6e55
authored
Jun 24, 2014
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #7082 from erbunao/fix_clipboard
Fix for copy-pasting formatted text to markdown area
parents
66541d8d
23626780
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
101 additions
and
1 deletion
+101
-1
app/assets/javascripts/markdown_area.js.coffee
app/assets/javascripts/markdown_area.js.coffee
+101
-1
No files found.
app/assets/javascripts/markdown_area.js.coffee
View file @
d7eb6e55
...
@@ -21,7 +21,6 @@ $(document).ready ->
...
@@ -21,7 +21,6 @@ $(document).ready ->
$
(
".div-dropzone"
).
append
divSpinner
$
(
".div-dropzone"
).
append
divSpinner
$
(
".div-dropzone-spinner"
).
append
iconSpinner
$
(
".div-dropzone-spinner"
).
append
iconSpinner
dropzone
=
$
(
".div-dropzone"
).
dropzone
(
dropzone
=
$
(
".div-dropzone"
).
dropzone
(
url
:
project_image_path_upload
url
:
project_image_path_upload
dictDefaultMessage
:
""
dictDefaultMessage
:
""
...
@@ -77,6 +76,107 @@ $(document).ready ->
...
@@ -77,6 +76,107 @@ $(document).ready ->
return
return
)
)
child
=
$
(
dropzone
[
0
]).
children
(
"textarea"
)
formatLink
=
(
str
)
->
"!["
+
str
.
alt
+
"]("
+
str
.
url
+
")"
handlePaste
=
(
e
)
->
e
.
preventDefault
()
my_event
=
e
.
originalEvent
if
my_event
.
clipboardData
and
my_event
.
clipboardData
.
items
processItem
(
my_event
)
processItem
=
(
e
)
->
image
=
isImage
(
e
)
if
image
filename
=
getFilename
(
e
)
or
"image.png"
text
=
"{{"
+
filename
+
"}}"
pasteText
(
text
)
uploadFile
image
.
getAsFile
(),
filename
else
text
=
e
.
clipboardData
.
getData
(
"text/plain"
)
pasteText
(
text
)
isImage
=
(
data
)
->
i
=
0
while
i
<
data
.
clipboardData
.
items
.
length
item
=
data
.
clipboardData
.
items
[
i
]
if
item
.
type
.
indexOf
(
"image"
)
isnt
-
1
return
item
i
++
return
false
pasteText
=
(
text
)
->
caretStart
=
$
(
child
)[
0
].
selectionStart
caretEnd
=
$
(
child
)[
0
].
selectionEnd
textEnd
=
$
(
child
).
val
().
length
beforeSelection
=
$
(
child
).
val
().
substring
0
,
caretStart
afterSelection
=
$
(
child
).
val
().
substring
caretEnd
,
textEnd
$
(
child
).
val
beforeSelection
+
text
+
afterSelection
$
(
".markdown-area"
).
trigger
"input"
getFilename
=
(
e
)
->
if
window
.
clipboardData
and
window
.
clipboardData
.
getData
value
=
window
.
clipboardData
.
getData
(
"Text"
)
else
if
e
.
clipboardData
and
e
.
clipboardData
.
getData
value
=
e
.
clipboardData
.
getData
(
"text/plain"
)
value
=
value
.
split
(
"
\r
"
)
value
.
first
()
uploadFile
=
(
item
,
filename
)
->
formData
=
new
FormData
()
formData
.
append
"markdown_img"
,
item
,
filename
$
.
ajax
url
:
project_image_path_upload
type
:
"POST"
data
:
formData
dataType
:
"json"
processData
:
false
contentType
:
false
headers
:
"X-CSRF-Token"
:
$
(
"meta[name=
\"
csrf-token
\"
]"
).
attr
(
"content"
)
beforeSend
:
->
showSpinner
()
closeAlertMessage
()
success
:
(
e
,
textStatus
,
response
)
->
insertToTextArea
(
filename
,
formatLink
(
response
.
responseJSON
.
link
))
error
:
(
response
)
->
showError
(
response
.
responseJSON
.
message
)
complete
:
->
closeSpinner
()
insertToTextArea
=
(
filename
,
url
)
->
$
(
child
).
val
(
index
,
val
)
->
val
.
replace
(
"{{"
+
filename
+
"}}"
,
url
+
"
\n
"
)
appendToTextArea
=
(
url
)
->
$
(
child
).
val
(
index
,
val
)
->
val
+
url
+
"
\n
"
showSpinner
=
(
e
)
->
$
(
".div-dropzone-spinner"
).
css
"opacity"
,
0.7
closeSpinner
=
->
$
(
".div-dropzone-spinner"
).
css
"opacity"
,
0
showError
=
(
message
)
->
checkIfMsgExists
=
$
(
".error-alert"
).
children
().
length
if
checkIfMsgExists
is
0
$
(
".error-alert"
).
append
divAlert
$
(
".div-dropzone-alert"
).
append
btnAlert
+
message
closeAlertMessage
=
->
$
(
".div-dropzone-alert"
).
alert
"close"
$
(
".markdown-selector"
).
click
(
e
)
->
$
(
".markdown-selector"
).
click
(
e
)
->
e
.
preventDefault
()
e
.
preventDefault
()
$
(
".div-dropzone"
).
click
()
$
(
".div-dropzone"
).
click
()
...
...
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