Skip to content

Instantly share code, notes, and snippets.

@seangaffney
Last active August 29, 2015 14:17
Show Gist options
  • Save seangaffney/e25fed7b56455ec182e5 to your computer and use it in GitHub Desktop.
Save seangaffney/e25fed7b56455ec182e5 to your computer and use it in GitHub Desktop.
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