Mercurial > zeropaste
annotate app/assets/javascripts/application.coffee @ 403:e0626046579a
Rearrange stuff.
author | nanaya <me@myconan.net> |
---|---|
date | Sun, 06 Sep 2015 04:32:02 +0900 |
parents | a18e19139f57 |
children | 3d434e15ddb1 |
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 newLocation ||= window.location.pathname | |
21 history.replaceState null, "", newLocation | |
22 | |
23 | |
402 | 24 markdownfy = (plaintext) -> |
25 reader = new commonmark.Parser | |
26 writer = new commonmark.HtmlRenderer(safe: true) | |
27 writer.render reader.parse(plaintext) | |
28 | |
29 | |
398 | 30 $(document).on "click", ".js-show-tab-pl", -> |
31 setHash() | |
32 | |
382 | 33 |
398 | 34 $(document).on "click", ".js-show-tab-hl", -> |
35 setHash "#hl" | |
36 $hlBox = $(".js-paste-hl") | |
37 return if $hlBox.data("processed") | |
38 | |
39 $hlBox.text pasteText() | |
40 | |
41 highlight = -> hljs.highlightBlock($hlBox[0]) | |
42 setTimeout highlight, 0 | |
43 | |
44 $hlBox.data "processed", true | |
45 | |
46 | |
47 $(document).on "click", ".js-show-tab-md", -> | |
48 setHash "#md" | |
49 $mdBox = $(".js-paste-md") | |
50 return if $mdBox.data("processed") | |
51 | |
402 | 52 $mdBox.html markdownfy(pasteText()) |
398 | 53 $mdBox.find("a").attr("rel", "nofollow") |
54 $mdBox.data "processed", true | |
55 | |
402 | 56 |
57 $(document).on "click", ".js-paste-preview-md", -> | |
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() |