diff app/assets/javascripts/application.coffee @ 402:a18e19139f57

Markdown preview \o/
author nanaya <me@myconan.net>
date Sun, 06 Sep 2015 04:20:50 +0900
parents 851432f21603
children 3d434e15ddb1
line wrap: on
line diff
--- a/app/assets/javascripts/application.coffee	Sun Sep 06 04:01:22 2015 +0900
+++ b/app/assets/javascripts/application.coffee	Sun Sep 06 04:20:50 2015 +0900
@@ -11,7 +11,7 @@
 
 
 pasteText = ->
-  $(".js-paste-pl").text()
+  $(".js-paste-paste").val() || $(".js-paste-pl").text()
 
 
 setHash = (newLocation = window.location.pathname) ->
@@ -21,6 +21,12 @@
   history.replaceState null, "", newLocation
 
 
+markdownfy = (plaintext) ->
+  reader = new commonmark.Parser
+  writer = new commonmark.HtmlRenderer(safe: true)
+  writer.render reader.parse(plaintext)
+
+
 $(document).on "click", ".js-show-tab-pl", ->
   setHash()
 
@@ -43,14 +49,17 @@
   $mdBox = $(".js-paste-md")
   return if $mdBox.data("processed")
 
-  reader = new commonmark.Parser
-  writer = new commonmark.HtmlRenderer(safe: true)
-  parsed = reader.parse pasteText()
-
-  $mdBox.html writer.render(parsed)
+  $mdBox.html markdownfy(pasteText())
   $mdBox.find("a").attr("rel", "nofollow")
   $mdBox.data "processed", true
 
+
+$(document).on "click", ".js-paste-preview-md", ->
+  return if pasteText() == ""
+  $(".js-paste-preview-md-box").html markdownfy(pasteText())
+  $(".js-paste-preview-md-modal").modal "show"
+
+
 $(document).on "ready", ->
   return if $(".js-showing-paste").length < 1