Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
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
edx
edx-platform
Commits
627aa216
Commit
627aa216
authored
Jul 26, 2012
by
Rocky Duan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve for multiple editor on page
parent
88242c2e
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
32 deletions
+39
-32
lms/static/coffee/src/customwmd.coffee
+32
-24
lms/static/coffee/src/discussion.coffee
+2
-0
lms/static/coffee/src/mathjax_delay_renderer.coffee
+5
-8
No files found.
lms/static/coffee/src/customwmd.coffee
View file @
627aa216
...
@@ -6,10 +6,6 @@ $ ->
...
@@ -6,10 +6,6 @@ $ ->
class
MathJaxProcessor
class
MathJaxProcessor
inlineMark
=
"$"
math
=
null
blocks
=
null
MATHSPLIT
=
///
(
MATHSPLIT
=
///
(
\$\$?
# normal inline or display delimiter
\$\$?
# normal inline or display delimiter
| \\(?:begin|end)\{[a-z]*\*?\}
# \begin{} \end{} style
| \\(?:begin|end)\{[a-z]*\*?\}
# \begin{} \end{} style
...
@@ -27,20 +23,26 @@ $ ->
...
@@ -27,20 +23,26 @@ $ ->
(?!`)
(?!`)
///gm
///gm
@
processMath
:
(
start
,
last
,
preProcess
)
=>
constructor
:
(
inlineMark
,
displayMark
)
->
block
=
blocks
.
slice
(
start
,
last
+
1
).
join
(
""
).
replace
(
/&/g
,
"&"
)
@
inlineMark
=
inlineMark
||
"$"
@
displayMark
=
displayMark
||
"$$"
@
math
=
null
@
blocks
=
null
processMath
:
(
start
,
last
,
preProcess
)
->
block
=
@
blocks
.
slice
(
start
,
last
+
1
).
join
(
""
).
replace
(
/&/g
,
"&"
)
.
replace
(
/</g
,
"<"
)
.
replace
(
/</g
,
"<"
)
.
replace
(
/>/g
,
">"
)
.
replace
(
/>/g
,
">"
)
if
HUB
.
Browser
.
isMSIE
if
HUB
.
Browser
.
isMSIE
block
=
block
.
replace
/(%[^\n]*)\n/g
,
"$1<br/>
\n
"
block
=
block
.
replace
/(%[^\n]*)\n/g
,
"$1<br/>
\n
"
blocks
[
i
]
=
""
for
i
in
[
start
+
1
..
last
]
@
blocks
[
i
]
=
""
for
i
in
[
start
+
1
..
last
]
blocks
[
start
]
=
"@@
#{
math
.
length
}
@@"
@
blocks
[
start
]
=
"@@
#{
@
math
.
length
}
@@"
block
=
preProcess
(
block
)
if
preProcess
block
=
preProcess
(
block
)
if
preProcess
math
.
push
block
@
math
.
push
block
@
removeMath
:
(
text
)
=
>
removeMath
:
(
text
)
-
>
math
=
[]
@
math
=
[]
start
=
end
=
last
=
null
start
=
end
=
last
=
null
braces
=
0
braces
=
0
...
@@ -54,13 +56,13 @@ $ ->
...
@@ -54,13 +56,13 @@ $ ->
else
else
deTilde
=
(
text
)
->
text
deTilde
=
(
text
)
->
text
blocks
=
_split
(
text
.
replace
(
/\r\n?/g
,
"
\n
"
),
MATHSPLIT
)
@
blocks
=
_split
(
text
.
replace
(
/\r\n?/g
,
"
\n
"
),
MATHSPLIT
)
for
current
in
[
1
...
blocks
.
length
]
by
2
for
current
in
[
1
...
@
blocks
.
length
]
by
2
block
=
blocks
[
current
]
block
=
@
blocks
[
current
]
if
block
.
charAt
(
0
)
==
"@"
if
block
.
charAt
(
0
)
==
"@"
blocks
[
current
]
=
"@@
#{
math
.
length
}
@@"
@
blocks
[
current
]
=
"@@
#{
@
math
.
length
}
@@"
math
.
push
block
@
math
.
push
block
else
if
start
else
if
start
if
block
==
end
if
block
==
end
if
braces
if
braces
...
@@ -79,7 +81,7 @@ $ ->
...
@@ -79,7 +81,7 @@ $ ->
else
if
block
==
"}"
and
braces
else
if
block
==
"}"
and
braces
--
braces
--
braces
else
else
if
block
==
inlineMark
or
block
==
"$$"
if
block
==
@
inlineMark
or
block
==
@
displayMark
start
=
current
start
=
current
end
=
block
end
=
block
braces
=
0
braces
=
0
...
@@ -92,18 +94,24 @@ $ ->
...
@@ -92,18 +94,24 @@ $ ->
@
processMath
(
start
,
last
,
deTilde
)
@
processMath
(
start
,
last
,
deTilde
)
start
=
end
=
last
=
null
start
=
end
=
last
=
null
deTilde
(
blocks
.
join
(
""
))
deTilde
(
@
blocks
.
join
(
""
))
@
replaceMath
:
(
text
)
=
>
replaceMath
:
(
text
)
-
>
text
=
text
.
replace
/@@(\d+)@@/g
,
(
$0
,
$1
)
=>
math
[
$1
]
text
=
text
.
replace
/@@(\d+)@@/g
,
(
$0
,
$1
)
=>
@
math
[
$1
]
math
=
null
@
math
=
null
text
text
if
Markdown
?
if
Markdown
?
Markdown
.
getMathCompatibleConverter
=
->
converter
=
Markdown
.
getSanitizingConverter
()
converter
=
Markdown
.
getSanitizingConverter
()
editor
=
new
Markdown
.
Editor
(
converter
)
processor
=
new
MathJaxProcessor
()
converter
.
hooks
.
chain
"preConversion"
,
MathJaxProcessor
.
removeMath
converter
.
hooks
.
chain
"preConversion"
,
processor
.
removeMath
converter
.
hooks
.
chain
"postConversion"
,
MathJaxProcessor
.
replaceMath
converter
.
hooks
.
chain
"postConversion"
,
processor
.
replaceMath
converter
Markdown
.
makeWmdEditor
=
(
appended_id
)
->
converter
=
Markdown
.
getMathCompatibleConverter
()
editor
=
new
Markdown
.
Editor
(
converter
,
appended_id
)
delayRenderer
=
new
MathJaxDelayRenderer
()
delayRenderer
=
new
MathJaxDelayRenderer
()
editor
.
hooks
.
chain
"onPreviewPush"
,
(
text
,
previewSet
)
->
editor
.
hooks
.
chain
"onPreviewPush"
,
(
text
,
previewSet
)
->
delayRenderer
.
render
delayRenderer
.
render
...
...
lms/static/coffee/src/discussion.coffee
View file @
627aa216
...
@@ -13,6 +13,8 @@ $ ->
...
@@ -13,6 +13,8 @@ $ ->
Discussion
.
bindDiscussionEvents
(
discussion
)
Discussion
.
bindDiscussionEvents
(
discussion
)
Discussion
.
initializeDiscussion
(
discussion
)
Discussion
.
initializeDiscussion
(
discussion
)
Markdown
.
makeWmdEditor
()
generateLocal
=
(
elem
)
->
generateLocal
=
(
elem
)
->
(
selector
)
->
$
(
elem
).
find
(
selector
)
(
selector
)
->
$
(
elem
).
find
(
selector
)
...
...
lms/static/coffee/src/mathjax_delay_renderer.coffee
View file @
627aa216
...
@@ -13,9 +13,7 @@ class @MathJaxDelayRenderer
...
@@ -13,9 +13,7 @@ class @MathJaxDelayRenderer
constructor
:
(
params
)
->
constructor
:
(
params
)
->
params
=
params
||
{}
params
=
params
||
{}
@
maxDelay
=
params
[
"maxDelay"
]
||
@
maxDelay
@
maxDelay
=
params
[
"maxDelay"
]
||
@
maxDelay
@
bufferId
=
params
[
"buffer"
]
||
@
bufferId
@
$buffer
=
$
(
"<div>"
).
attr
(
"id"
,
@
bufferId
).
css
(
"display"
,
"none"
).
appendTo
(
$
(
"body"
))
if
not
$
(
"#
#{
@
bufferId
}
"
).
length
$
(
"<div>"
).
attr
(
"id"
,
@
bufferId
).
css
(
"display"
,
"none"
).
appendTo
(
$
(
"body"
))
# render: (params) ->
# render: (params) ->
# params:
# params:
...
@@ -35,7 +33,6 @@ class @MathJaxDelayRenderer
...
@@ -35,7 +33,6 @@ class @MathJaxDelayRenderer
if
not
text
?
if
not
text
?
text
=
$
(
elem
).
html
()
text
=
$
(
elem
).
html
()
preprocessor
=
params
[
"preprocessor"
]
preprocessor
=
params
[
"preprocessor"
]
buffer
=
$
(
"#
#{
@
bufferId
}
"
)
if
params
[
"delay"
]
==
false
if
params
[
"delay"
]
==
false
if
preprocessor
?
if
preprocessor
?
...
@@ -54,20 +51,20 @@ class @MathJaxDelayRenderer
...
@@ -54,20 +51,20 @@ class @MathJaxDelayRenderer
prevTime
=
getTime
()
prevTime
=
getTime
()
if
preprocessor
?
if
preprocessor
?
text
=
preprocessor
(
text
)
text
=
preprocessor
(
text
)
buffer
.
html
(
text
)
@
$
buffer
.
html
(
text
)
curTime
=
getTime
()
curTime
=
getTime
()
@
elapsedTime
=
curTime
-
prevTime
@
elapsedTime
=
curTime
-
prevTime
if
MathJax
if
MathJax
prevTime
=
getTime
()
prevTime
=
getTime
()
@
mathjaxRunning
=
true
@
mathjaxRunning
=
true
MathJax
.
Hub
.
Queue
[
"Typeset"
,
MathJax
.
Hub
,
buffer
.
attr
(
"id"
)],
=>
MathJax
.
Hub
.
Queue
[
"Typeset"
,
MathJax
.
Hub
,
@
$
buffer
.
attr
(
"id"
)],
=>
@
mathjaxRunning
=
false
@
mathjaxRunning
=
false
curTime
=
getTime
()
curTime
=
getTime
()
@
mathjaxDelay
=
curTime
-
prevTime
@
mathjaxDelay
=
curTime
-
prevTime
if
previewSetter
if
previewSetter
previewSetter
(
$
(
buffer
).
html
())
previewSetter
(
$
(
@
$
buffer
).
html
())
else
else
$
(
elem
).
html
(
$
(
buffer
).
html
())
$
(
elem
).
html
(
$
(
@
$
buffer
).
html
())
else
else
@
mathjaxDelay
=
0
@
mathjaxDelay
=
0
@
mathjaxTimeout
=
window
.
setTimeout
(
renderer
,
delay
)
@
mathjaxTimeout
=
window
.
setTimeout
(
renderer
,
delay
)
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