Commit 0560bb7e by Rocky Duan

add hide similar post button

parent 0863e346
......@@ -62,6 +62,15 @@ initializeFollowDiscussion = (discussion) ->
$local(".discussion-new-post").show()
handleSimilarPost = (elem) ->
$title = $local(".new-post-title")
$wrapper = $local(".new-post-similar-posts-wrapper")
$similarPosts = $local(".new-post-similar-posts")
prevText = $title.attr("prev-text")
text = $title.val()
if text == prevText
if $local(".similar-post").length
$wrapper.show()
else if $.trim(text).length
Discussion.safeAjax
$elem: $(elem)
url: Discussion.urlFor 'search_similar_threads', id
......@@ -70,8 +79,7 @@ initializeFollowDiscussion = (discussion) ->
data:
text: $local(".new-post-title").val()
success: (response, textStatus) ->
$wrapper = $local(".new-post-similar-posts-wrapper")
$similarPosts = $local(".new-post-similar-posts")
console.log "request"
$similarPosts.empty()
if $.type(response) == "array" and response.length
$wrapper.show()
......@@ -83,6 +91,9 @@ initializeFollowDiscussion = (discussion) ->
.appendTo($similarPosts)
else
$wrapper.hide()
else
$wrapper.hide()
$title.attr("prev-text", text)
handleNewPost = (elem) ->
newPostForm = $local(".new-post-form")
......@@ -102,6 +113,9 @@ initializeFollowDiscussion = (discussion) ->
$local(".new-post-title").blur ->
handleSimilarPost(this)
$local(".hide-similar-posts").click ->
$local(".new-post-similar-posts-wrapper").hide()
$local(".discussion-submit-post").click ->
handleSubmitNewPost(this)
$local(".discussion-cancel-post").click ->
......
......@@ -11,7 +11,7 @@ Discussion = @Discussion
<ul class="discussion-errors"></ul>
<input type="text" class="new-post-title title-input" placeholder="Title"/>
<div class="new-post-similar-posts-wrapper" style="display: none">
Do you mean...
Do you mean... <a class="hide-similar-posts" href="javascript:void(0)">No you got it wrong lol</a>
<div class="new-post-similar-posts"></div>
</div>
<div class="new-post-body body-input"></div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment