Last active
August 29, 2015 14:17
-
-
Save seangaffney/e25fed7b56455ec182e5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MarkdownPreview | |
constructor: (element) -> | |
@$element = $(element) | |
@$preview = $("##{@$element.attr("id")}-preview") | |
if @$element.val?() | |
@get_preview() | |
throttled_get_preview = _.throttle @get_preview(), 1000 | |
@$element.keyup => | |
console.log 'keyup' | |
throttled_get_preview() | |
get_preview: => | |
text = @$element.val() | |
console.log 'word' | |
request = $.post "/admin/markdown_preview", {text: text} | |
request.success @success | |
request.fail @error | |
success: (data) => | |
@$preview.html(data.html) | |
error: (data) => | |
@$preview.html("There was a problem generating the preview. Please try again.") | |
Featurette.register("markdown-preview", MarkdownPreview) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment