Merge branch 'master' of github.com:dementrock/mitx into discussion
This commit is contained in:
@@ -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,33 +23,26 @@ $ ->
|
|||||||
(?!`)
|
(?!`)
|
||||||
///gm
|
///gm
|
||||||
|
|
||||||
###HUB.Queue ->
|
constructor: (inlineMark, displayMark) ->
|
||||||
console.log "initializing"
|
@inlineMark = inlineMark || "$"
|
||||||
renderReady = true
|
@displayMark = displayMark || "$$"
|
||||||
HUB.processUpdateTime = 50
|
@math = null
|
||||||
HUB.Config
|
@blocks = null
|
||||||
"HTML-CSS":
|
|
||||||
EqnChunk: 10
|
|
||||||
EqnChunkFactor: 1
|
|
||||||
SVG:
|
|
||||||
EqnChunk: 10
|
|
||||||
EqnChunkFactor: 1
|
|
||||||
###
|
|
||||||
|
|
||||||
@processMath: (start, last, preProcess) =>
|
processMath: (start, last, preProcess) ->
|
||||||
block = blocks.slice(start, last + 1).join("").replace(/&/g, "&")
|
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
|
||||||
|
|
||||||
@@ -67,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
|
||||||
@@ -92,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
|
||||||
@@ -105,75 +94,38 @@ $ ->
|
|||||||
@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
|
||||||
|
|
||||||
@updateMathJax: =>
|
|
||||||
HUB.Queue(["Typeset", HUB, "wmd-preview"])
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
###
|
|
||||||
if not HUB.Cancel? #and 1 == 2
|
|
||||||
HUB.cancelTypeset = false
|
|
||||||
CANCELMESSAGE = "MathJax Canceled"
|
|
||||||
|
|
||||||
HOOKS = [
|
|
||||||
{
|
|
||||||
name: "HTML-CSS Jax Config"
|
|
||||||
engine: -> window["MathJax"].OutputJax["HTML-CSS"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "SVG Jax Config"
|
|
||||||
engine: -> window["MathJax"].OutputJax["SVG"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "TeX Jax Config"
|
|
||||||
engine: -> window["MathJax"].InputJax.TeX
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
for hook in HOOKS
|
|
||||||
do (hook) ->
|
|
||||||
HUB.Register.StartupHook hook.name, ->
|
|
||||||
engine = hook.engine()
|
|
||||||
engine.Augment
|
|
||||||
Translate: (script, state) ->
|
|
||||||
console.log "translating"
|
|
||||||
if HUB.cancelTypeset or state.cancelled
|
|
||||||
throw Error(CANCELMESSAGE)
|
|
||||||
engine.Translate.call(engine, script, state)
|
|
||||||
|
|
||||||
prevProcessError = HUB.processError
|
|
||||||
HUB.processError = (error, state, type) ->
|
|
||||||
if error.message != CANCELMESSAGE
|
|
||||||
return prevProcessError.call(HUB, error, state, type)
|
|
||||||
else
|
|
||||||
console.log "handling message"
|
|
||||||
MathJax.Message.Clear(0, 0)
|
|
||||||
state.jaxIds = []
|
|
||||||
state.jax = {}
|
|
||||||
state.scripts = []
|
|
||||||
state.i = state.j = 0
|
|
||||||
state.cancelled = true
|
|
||||||
return null
|
|
||||||
|
|
||||||
HUB.Cancel = ->
|
|
||||||
this.cancelTypeset = true
|
|
||||||
###
|
|
||||||
|
|
||||||
if Markdown?
|
if Markdown?
|
||||||
converter = Markdown.getSanitizingConverter()
|
Markdown.getMathCompatibleConverter = ->
|
||||||
editor = new Markdown.Editor(converter)
|
converter = Markdown.getSanitizingConverter()
|
||||||
converter.hooks.chain "preConversion", MathJaxProcessor.removeMath
|
processor = new MathJaxProcessor()
|
||||||
converter.hooks.chain "postConversion", MathJaxProcessor.replaceMath
|
converter.hooks.chain "preConversion", processor.removeMath
|
||||||
delayRenderer = new MathJaxDelayRenderer()
|
converter.hooks.chain "postConversion", processor.replaceMath
|
||||||
editor.hooks.chain "onPreviewPush", (text, previewSet) ->
|
converter
|
||||||
delayRenderer.render
|
|
||||||
text: text
|
Markdown.makeWmdEditor = (elem, appended_id) ->
|
||||||
previewSetter: previewSet
|
$elem = $(elem)
|
||||||
editor.run()
|
if not $elem.length
|
||||||
|
console.log "warning: elem for makeWmdEditor doesn't exist"
|
||||||
|
return
|
||||||
|
if not $elem.find(".wmd-panel").length
|
||||||
|
_append = appended_id || ""
|
||||||
|
$wmdPanel = $("<div>").addClass("wmd-panel")
|
||||||
|
.append($("<div>").attr("id", "wmd-button-bar#{_append}"))
|
||||||
|
.append($("<textarea>").addClass("wmd-input").attr("id", "wmd-input#{_append}"))
|
||||||
|
.append($("<div>").attr("id", "wmd-preview#{_append}").addClass("wmd-panel wmd-preview"))
|
||||||
|
$elem.append($wmdPanel)
|
||||||
|
converter = Markdown.getMathCompatibleConverter()
|
||||||
|
editor = new Markdown.Editor(converter, appended_id)
|
||||||
|
delayRenderer = new MathJaxDelayRenderer()
|
||||||
|
editor.hooks.chain "onPreviewPush", (text, previewSet) ->
|
||||||
|
delayRenderer.render
|
||||||
|
text: text
|
||||||
|
previewSetter: previewSet
|
||||||
|
editor.run()
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ $ ->
|
|||||||
Discussion.bindDiscussionEvents(discussion)
|
Discussion.bindDiscussionEvents(discussion)
|
||||||
Discussion.initializeDiscussion(discussion)
|
Discussion.initializeDiscussion(discussion)
|
||||||
|
|
||||||
|
|
||||||
generateLocal = (elem) ->
|
generateLocal = (elem) ->
|
||||||
(selector) -> $(elem).find(selector)
|
(selector) -> $(elem).find(selector)
|
||||||
|
|
||||||
@@ -50,6 +51,7 @@ Discussion =
|
|||||||
window.location.reload()
|
window.location.reload()
|
||||||
|
|
||||||
initializeDiscussion: (discussion) ->
|
initializeDiscussion: (discussion) ->
|
||||||
|
|
||||||
initializeVote = (index, content) ->
|
initializeVote = (index, content) ->
|
||||||
$content = $(content)
|
$content = $(content)
|
||||||
$local = generateLocal($content.children(".discussion-content"))
|
$local = generateLocal($content.children(".discussion-content"))
|
||||||
@@ -85,6 +87,10 @@ Discussion =
|
|||||||
watchDiscussion = generateDiscussionLink("discussion-watch-discussion", "Watch", handleWatchDiscussion)
|
watchDiscussion = generateDiscussionLink("discussion-watch-discussion", "Watch", handleWatchDiscussion)
|
||||||
$local(".discussion-title-wrapper").append(watchDiscussion)
|
$local(".discussion-title-wrapper").append(watchDiscussion)
|
||||||
|
|
||||||
|
newPostBody = $(discussion).find(".new-post-body")
|
||||||
|
if newPostBody.length
|
||||||
|
Markdown.makeWmdEditor newPostBody, "-new-post-body-#{$(discussion).attr('_id')}"
|
||||||
|
|
||||||
initializeWatchThreads = (index, thread) ->
|
initializeWatchThreads = (index, thread) ->
|
||||||
$thread = $(thread)
|
$thread = $(thread)
|
||||||
id = $thread.attr("_id")
|
id = $thread.attr("_id")
|
||||||
@@ -147,7 +153,7 @@ Discussion =
|
|||||||
else
|
else
|
||||||
editView = $("<div>").addClass("discussion-content-edit")
|
editView = $("<div>").addClass("discussion-content-edit")
|
||||||
|
|
||||||
textarea = $("<textarea>").addClass("comment-edit")
|
textarea = $("<div>").addClass("comment-edit")
|
||||||
editView.append(textarea)
|
editView.append(textarea)
|
||||||
|
|
||||||
anonymousCheckbox = $("<input>").attr("type", "checkbox")
|
anonymousCheckbox = $("<input>").attr("type", "checkbox")
|
||||||
@@ -156,7 +162,8 @@ Discussion =
|
|||||||
anonymousLabel = $("<label>").attr("for", "discussion-post-anonymously-#{id}")
|
anonymousLabel = $("<label>").attr("for", "discussion-post-anonymously-#{id}")
|
||||||
.html("post anonymously")
|
.html("post anonymously")
|
||||||
editView.append(anonymousCheckbox).append(anonymousLabel)
|
editView.append(anonymousCheckbox).append(anonymousLabel)
|
||||||
|
|
||||||
|
|
||||||
if $discussionContent.parent(".thread").attr("_id") not in $$user_info.subscribed_thread_ids
|
if $discussionContent.parent(".thread").attr("_id") not in $$user_info.subscribed_thread_ids
|
||||||
watchCheckbox = $("<input>").attr("type", "checkbox")
|
watchCheckbox = $("<input>").attr("type", "checkbox")
|
||||||
.addClass("discussion-auto-watch")
|
.addClass("discussion-auto-watch")
|
||||||
@@ -167,6 +174,8 @@ Discussion =
|
|||||||
editView.append(watchCheckbox).append(watchLabel)
|
editView.append(watchCheckbox).append(watchLabel)
|
||||||
|
|
||||||
$discussionContent.append(editView)
|
$discussionContent.append(editView)
|
||||||
|
|
||||||
|
Markdown.makeWmdEditor $local(".comment-edit"), "-comment-edit-#{id}"
|
||||||
cancelReply = generateDiscussionLink("discussion-cancel-reply", "Cancel", handleCancelReply)
|
cancelReply = generateDiscussionLink("discussion-cancel-reply", "Cancel", handleCancelReply)
|
||||||
submitReply = generateDiscussionLink("discussion-submit-reply", "Submit", handleSubmitReply)
|
submitReply = generateDiscussionLink("discussion-submit-reply", "Submit", handleSubmitReply)
|
||||||
$local(".discussion-link").hide()
|
$local(".discussion-link").hide()
|
||||||
@@ -190,7 +199,8 @@ Discussion =
|
|||||||
url = Discussion.urlFor('create_sub_comment', id)
|
url = Discussion.urlFor('create_sub_comment', id)
|
||||||
else
|
else
|
||||||
return
|
return
|
||||||
body = $local(".comment-edit").val()
|
|
||||||
|
body = $local("#wmd-input-comment-edit-#{id}").val()
|
||||||
|
|
||||||
anonymous = false || $local(".discussion-post-anonymously").is(":checked")
|
anonymous = false || $local(".discussion-post-anonymously").is(":checked")
|
||||||
autowatch = false || $local(".discussion-auto-watch").is(":checked")
|
autowatch = false || $local(".discussion-auto-watch").is(":checked")
|
||||||
@@ -225,6 +235,8 @@ Discussion =
|
|||||||
$discussionNonContent = $discussion.children(".discussion-non-content")
|
$discussionNonContent = $discussion.children(".discussion-non-content")
|
||||||
$local = (selector) -> $discussionNonContent.find(selector)
|
$local = (selector) -> $discussionNonContent.find(selector)
|
||||||
|
|
||||||
|
id = $discussion.attr("_id")
|
||||||
|
|
||||||
handleSearch = (text, isSearchWithinBoard) ->
|
handleSearch = (text, isSearchWithinBoard) ->
|
||||||
if text.length
|
if text.length
|
||||||
if $local(".discussion-search-within-board").is(":checked")
|
if $local(".discussion-search-within-board").is(":checked")
|
||||||
@@ -234,7 +246,7 @@ Discussion =
|
|||||||
|
|
||||||
handleSubmitNewThread = (elem) ->
|
handleSubmitNewThread = (elem) ->
|
||||||
title = $local(".new-post-title").val()
|
title = $local(".new-post-title").val()
|
||||||
body = $local(".new-post-body").val()
|
body = $local("#wmd-input-new-post-body-#{id}").val()
|
||||||
url = Discussion.urlFor('create_thread', $local(".new-post-form").attr("_id"))
|
url = Discussion.urlFor('create_thread', $local(".new-post-form").attr("_id"))
|
||||||
$.post url, {title: title, body: body}, (response, textStatus) ->
|
$.post url, {title: title, body: body}, (response, textStatus) ->
|
||||||
if textStatus == "success"
|
if textStatus == "success"
|
||||||
|
|||||||
@@ -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
|
|||||||
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
|
|||||||
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)
|
||||||
|
|||||||
@@ -91,6 +91,7 @@ $discussion_input_width: 60%;
|
|||||||
.discussion-right-wrapper {
|
.discussion-right-wrapper {
|
||||||
min-height: 40px;
|
min-height: 40px;
|
||||||
float: left;
|
float: left;
|
||||||
|
width: 70%;
|
||||||
}
|
}
|
||||||
.new-post-form {
|
.new-post-form {
|
||||||
.new-post-title, .new-post-body {
|
.new-post-title, .new-post-body {
|
||||||
@@ -190,7 +191,6 @@ $discussion_input_width: 60%;
|
|||||||
|
|
||||||
.wmd-panel
|
.wmd-panel
|
||||||
{
|
{
|
||||||
margin-left: 25%;
|
|
||||||
margin-right: 25%;
|
margin-right: 25%;
|
||||||
width: 50%;
|
width: 50%;
|
||||||
min-width: 500px;
|
min-width: 500px;
|
||||||
|
|||||||
@@ -8,14 +8,10 @@
|
|||||||
${search_bar}
|
${search_bar}
|
||||||
<form class="new-post-form" _id="${discussion_id}">
|
<form class="new-post-form" _id="${discussion_id}">
|
||||||
<input type="text" class="new-post-title" placeholder="Title"/>
|
<input type="text" class="new-post-title" placeholder="Title"/>
|
||||||
<textarea class="new-post-body"></textarea>
|
<div class="new-post-body">
|
||||||
|
</div>
|
||||||
<a class="discussion-new-post" href="javascript:void(0)">New Post</a>
|
<a class="discussion-new-post" href="javascript:void(0)">New Post</a>
|
||||||
<div class="wmd-panel">
|
|
||||||
<div id="wmd-button-bar"></div>
|
|
||||||
<textarea class="wmd-input" id="wmd-input">
|
|
||||||
</textarea>
|
|
||||||
<div id="wmd-preview" class="wmd-panel wmd-preview"></div>
|
|
||||||
</div>
|
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
% for thread in threads:
|
% for thread in threads:
|
||||||
|
|||||||
@@ -41,14 +41,16 @@
|
|||||||
% for comment in comments:
|
% for comment in comments:
|
||||||
<div class="comment" _id="${comment['id']}">
|
<div class="comment" _id="${comment['id']}">
|
||||||
<div class="discussion-content">
|
<div class="discussion-content">
|
||||||
${render_vote(comment)}
|
<div class="discussion-upper-wrapper clearfix">
|
||||||
<div class="discussion-right-wrapper">
|
${render_vote(comment)}
|
||||||
<div class="discussion-content-view">
|
<div class="discussion-right-wrapper">
|
||||||
<a class="comment-body" name="${comment['id']}">${comment['body']}</a>
|
<div class="discussion-content-view">
|
||||||
<div class="info">
|
<a class="comment-body" name="${comment['id']}">${comment['body']}</a>
|
||||||
${render_info(comment)}
|
<div class="info">
|
||||||
${render_reply()}
|
${render_info(comment)}
|
||||||
${render_edit()}
|
${render_reply()}
|
||||||
|
${render_edit()}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user