Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
410e24a3
Commit
410e24a3
authored
Sep 22, 2014
by
RawKStar77
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename returnSelection() to userSelection(), remove unneeded parentheses, fix spelling error
parent
eb0c163c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
8 deletions
+9
-8
markdown.coffee
h/static/scripts/directives/markdown.coffee
+9
-8
No files found.
h/static/scripts/directives/markdown.coffee
View file @
410e24a3
...
...
@@ -15,7 +15,7 @@ markdown = ['$filter', '$timeout', '$window', ($filter, $timeout, $window) ->
output
=
elem
.
find
(
'div'
)[
1
]
textarea
=
input
[
0
]
return
Selection
=
->
user
Selection
=
->
ourIframeSelection
=
$window
.
getSelection
().
toString
()
if
textarea
.
selectionStart
!=
undefined
startPos
=
textarea
.
selectionStart
...
...
@@ -33,18 +33,19 @@ markdown = ['$filter', '$timeout', '$window', ($filter, $timeout, $window) ->
start
:
startPos
end
:
endPos
}
input
.
focus
()
return
selection
insertMarkup
=
(
value
,
selectionStart
,
selectionEnd
)
->
# New value is set for the textarea
textarea
.
value
=
value
# A new selection is set, or the curs
u
r is positioned inside the textarea.
# A new selection is set, or the curs
o
r is positioned inside the textarea.
textarea
.
selectionStart
=
selectionStart
textarea
.
selectionEnd
=
selectionEnd
# Focus the textarea
textarea
.
focus
()
applyInlineMarkup
=
(
markup
,
innertext
)
->
text
=
return
Selection
()
text
=
user
Selection
()
if
text
.
selection
==
""
newtext
=
text
.
before
+
markup
+
innertext
+
markup
+
text
.
after
start
=
(
text
.
before
+
markup
).
length
...
...
@@ -52,7 +53,7 @@ markdown = ['$filter', '$timeout', '$window', ($filter, $timeout, $window) ->
insertMarkup
(
newtext
,
start
,
end
)
else
# Check to see if markup has already been applied before to the selection.
slice1
=
text
.
before
.
slice
(
(
text
.
before
.
length
-
markup
.
length
)
)
slice1
=
text
.
before
.
slice
(
text
.
before
.
length
-
markup
.
length
)
slice2
=
text
.
after
.
slice
(
0
,
markup
.
length
)
if
slice1
==
markup
and
slice2
==
markup
# Remove markup
...
...
@@ -77,7 +78,7 @@ markdown = ['$filter', '$timeout', '$window', ($filter, $timeout, $window) ->
applyInlineMarkup
(
"$$"
,
"LaTex"
)
scope
.
insertLink
=
->
text
=
return
Selection
()
text
=
user
Selection
()
if
text
.
selection
==
""
newtext
=
text
.
before
+
"[Link Text](https://example.com)"
+
text
.
after
start
=
text
.
before
.
length
+
1
...
...
@@ -93,7 +94,7 @@ markdown = ['$filter', '$timeout', '$window', ($filter, $timeout, $window) ->
insertMarkup
(
newtext
,
start
,
end
)
scope
.
insertIMG
=
->
text
=
return
Selection
()
text
=
user
Selection
()
if
text
.
selection
==
""
newtext
=
text
.
before
+
"![Image Description](https://yourimage.jpg)"
+
text
.
after
start
=
text
.
before
.
length
+
21
...
...
@@ -109,7 +110,7 @@ markdown = ['$filter', '$timeout', '$window', ($filter, $timeout, $window) ->
insertMarkup
(
newtext
,
start
,
end
)
scope
.
applyBlockMarkup
=
(
markup
)
->
text
=
return
Selection
()
text
=
user
Selection
()
if
text
.
selection
!=
""
newstring
=
""
index
=
text
.
before
.
length
...
...
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