Mercurial > zeropaste
annotate app/assets/javascripts/application.coffee @ 427:cbfb3a0a9d2e
Update gems
author | nanaya <me@myconan.net> |
---|---|
date | Sat, 14 Nov 2015 20:43:49 +0900 |
parents | f0b4d6bec50e |
children | 1fc5ddcde386 |
rev | line source |
---|---|
381
bfc5ad3f7dc5
Use rails' builtin jquery instead of external one.
nanaya <me@myconan.net>
parents:
379
diff
changeset
|
1 #= require jquery |
421 | 2 #= require bootstrap/transition |
3 #= require bootstrap/collapse | |
4 #= require bootstrap/modal | |
5 #= require bootstrap/tab | |
398 | 6 #= require highlightjs |
7 #= require commonmark | |
8 | |
9 $(document).on "click", ".js-paste-clear", (e) -> | |
10 e.preventDefault() | |
11 $(".js-paste-paste") | |
12 .val("") | |
13 .focus() | |
14 | |
15 | |
16 pasteText = -> | |
402 | 17 $(".js-paste-paste").val() || $(".js-paste-pl").text() |
398 | 18 |
19 | |
20 setHash = (newLocation = window.location.pathname) -> | |
21 return unless history.replaceState | |
22 | |
23 history.replaceState null, "", newLocation | |
24 | |
25 | |
402 | 26 markdownfy = (plaintext) -> |
27 reader = new commonmark.Parser | |
28 writer = new commonmark.HtmlRenderer(safe: true) | |
29 writer.render reader.parse(plaintext) | |
30 | |
31 | |
398 | 32 $(document).on "click", ".js-show-tab-pl", -> |
33 setHash() | |
34 | |
382 | 35 |
398 | 36 $(document).on "click", ".js-show-tab-hl", -> |
37 setHash "#hl" | |
38 $hlBox = $(".js-paste-hl") | |
39 return if $hlBox.data("processed") | |
40 | |
41 $hlBox.text pasteText() | |
42 | |
43 highlight = -> hljs.highlightBlock($hlBox[0]) | |
44 setTimeout highlight, 0 | |
45 | |
46 $hlBox.data "processed", true | |
47 | |
48 | |
49 $(document).on "click", ".js-show-tab-md", -> | |
50 setHash "#md" | |
51 $mdBox = $(".js-paste-md") | |
52 return if $mdBox.data("processed") | |
53 | |
402 | 54 $mdBox.html markdownfy(pasteText()) |
398 | 55 $mdBox.find("a").attr("rel", "nofollow") |
56 $mdBox.data "processed", true | |
57 | |
402 | 58 |
405
26c1b0b8edbe
Don't add hash when clicking preview.
nanaya <me@myconan.net>
parents:
404
diff
changeset
|
59 $(document).on "click", ".js-paste-preview-md", (e) -> |
26c1b0b8edbe
Don't add hash when clicking preview.
nanaya <me@myconan.net>
parents:
404
diff
changeset
|
60 e.preventDefault() |
402 | 61 return if pasteText() == "" |
62 $(".js-paste-preview-md-box").html markdownfy(pasteText()) | |
63 $(".js-paste-preview-md-modal").modal "show" | |
64 | |
65 | |
398 | 66 $(document).on "ready", -> |
416 | 67 return unless $(".js-showing-paste").length |
398 | 68 |
69 format = window.location.hash.slice(1) | |
70 $(".js-show-tab-#{format}").click() | |
417
080dd141898c
Add support for explicit highlighter languages
nanaya <me@myconan.net>
parents:
416
diff
changeset
|
71 |
080dd141898c
Add support for explicit highlighter languages
nanaya <me@myconan.net>
parents:
416
diff
changeset
|
72 |
080dd141898c
Add support for explicit highlighter languages
nanaya <me@myconan.net>
parents:
416
diff
changeset
|
73 $(document).on "ready", -> |
080dd141898c
Add support for explicit highlighter languages
nanaya <me@myconan.net>
parents:
416
diff
changeset
|
74 $languageSelectBox = $("#paste_language") |
080dd141898c
Add support for explicit highlighter languages
nanaya <me@myconan.net>
parents:
416
diff
changeset
|
75 return unless $languageSelectBox.length |
080dd141898c
Add support for explicit highlighter languages
nanaya <me@myconan.net>
parents:
416
diff
changeset
|
76 |
080dd141898c
Add support for explicit highlighter languages
nanaya <me@myconan.net>
parents:
416
diff
changeset
|
77 for language in hljs.listLanguages().sort() |
080dd141898c
Add support for explicit highlighter languages
nanaya <me@myconan.net>
parents:
416
diff
changeset
|
78 $languageSelectBox.append $("<option />", value: language, text: language) |