Mercurial > zeropaste
annotate app/assets/javascripts/application.coffee @ 412:634366b67312
Add extra padding so the links aren't stuck to bottom.
author | nanaya <me@myconan.net> |
---|---|
date | Mon, 07 Sep 2015 21:54:39 +0900 |
parents | 26c1b0b8edbe |
children | c4c8214fb0b2 |
rev | line source |
---|---|
381
bfc5ad3f7dc5
Use rails' builtin jquery instead of external one.
nanaya <me@myconan.net>
parents:
379
diff
changeset
|
1 #= require jquery |
398 | 2 #= require bootstrap |
3 #= require highlightjs | |
4 #= require commonmark | |
5 | |
6 $(document).on "click", ".js-paste-clear", (e) -> | |
7 e.preventDefault() | |
8 $(".js-paste-paste") | |
9 .val("") | |
10 .focus() | |
11 | |
12 | |
13 pasteText = -> | |
402 | 14 $(".js-paste-paste").val() || $(".js-paste-pl").text() |
398 | 15 |
16 | |
17 setHash = (newLocation = window.location.pathname) -> | |
18 return unless history.replaceState | |
19 | |
20 history.replaceState null, "", newLocation | |
21 | |
22 | |
402 | 23 markdownfy = (plaintext) -> |
24 reader = new commonmark.Parser | |
25 writer = new commonmark.HtmlRenderer(safe: true) | |
26 writer.render reader.parse(plaintext) | |
27 | |
28 | |
398 | 29 $(document).on "click", ".js-show-tab-pl", -> |
30 setHash() | |
31 | |
382 | 32 |
398 | 33 $(document).on "click", ".js-show-tab-hl", -> |
34 setHash "#hl" | |
35 $hlBox = $(".js-paste-hl") | |
36 return if $hlBox.data("processed") | |
37 | |
38 $hlBox.text pasteText() | |
39 | |
40 highlight = -> hljs.highlightBlock($hlBox[0]) | |
41 setTimeout highlight, 0 | |
42 | |
43 $hlBox.data "processed", true | |
44 | |
45 | |
46 $(document).on "click", ".js-show-tab-md", -> | |
47 setHash "#md" | |
48 $mdBox = $(".js-paste-md") | |
49 return if $mdBox.data("processed") | |
50 | |
402 | 51 $mdBox.html markdownfy(pasteText()) |
398 | 52 $mdBox.find("a").attr("rel", "nofollow") |
53 $mdBox.data "processed", true | |
54 | |
402 | 55 |
405
26c1b0b8edbe
Don't add hash when clicking preview.
nanaya <me@myconan.net>
parents:
404
diff
changeset
|
56 $(document).on "click", ".js-paste-preview-md", (e) -> |
26c1b0b8edbe
Don't add hash when clicking preview.
nanaya <me@myconan.net>
parents:
404
diff
changeset
|
57 e.preventDefault() |
402 | 58 return if pasteText() == "" |
59 $(".js-paste-preview-md-box").html markdownfy(pasteText()) | |
60 $(".js-paste-preview-md-modal").modal "show" | |
61 | |
62 | |
398 | 63 $(document).on "ready", -> |
64 return if $(".js-showing-paste").length < 1 | |
65 | |
66 format = window.location.hash.slice(1) | |
67 $(".js-show-tab-#{format}").click() |