Mercurial > zeropaste
annotate app/assets/javascripts/application.coffee @ 398:851432f21603
Nope, failing at redesigning.
author | nanaya <me@myconan.net> |
---|---|
date | Sun, 06 Sep 2015 03:52:52 +0900 |
parents | 8ceb373e32d8 |
children | a18e19139f57 |
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 = -> | |
14 $(".js-paste-pl").text() | |
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 | |
24 $(document).on "click", ".js-show-tab-pl", -> | |
25 setHash() | |
26 | |
382 | 27 |
398 | 28 $(document).on "click", ".js-show-tab-hl", -> |
29 setHash "#hl" | |
30 $hlBox = $(".js-paste-hl") | |
31 return if $hlBox.data("processed") | |
32 | |
33 $hlBox.text pasteText() | |
34 | |
35 highlight = -> hljs.highlightBlock($hlBox[0]) | |
36 setTimeout highlight, 0 | |
37 | |
38 $hlBox.data "processed", true | |
39 | |
40 | |
41 $(document).on "click", ".js-show-tab-md", -> | |
42 setHash "#md" | |
43 $mdBox = $(".js-paste-md") | |
44 return if $mdBox.data("processed") | |
45 | |
46 reader = new commonmark.Parser | |
47 writer = new commonmark.HtmlRenderer(safe: true) | |
48 parsed = reader.parse pasteText() | |
49 | |
50 $mdBox.html writer.render(parsed) | |
51 $mdBox.find("a").attr("rel", "nofollow") | |
52 $mdBox.data "processed", true | |
53 | |
54 $(document).on "ready", -> | |
55 return if $(".js-showing-paste").length < 1 | |
56 | |
57 format = window.location.hash.slice(1) | |
58 $(".js-show-tab-#{format}").click() |