Mercurial > zeropaste
annotate app/assets/javascripts/application.coffee @ 455:76153b601d7e
No more zoom on mobile
author | nanaya <me@nanaya.pro> |
---|---|
date | Tue, 14 Nov 2017 22:40:10 +0900 |
parents | 1fc5ddcde386 |
children |
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 | |
442 | 16 loadLanguageItems = -> |
17 $languageSelectBox = $("#paste_language") | |
18 return unless $languageSelectBox.length | |
398 | 19 |
442 | 20 for language in hljs.listLanguages().sort() |
21 $languageSelectBox.append $("<option />", value: language, text: language) | |
398 | 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 | |
442 | 30 pasteText = -> |
31 $(".js-paste-paste").val() || $(".js-paste-pl").text() | |
398 | 32 |
382 | 33 |
442 | 34 highlightText = -> |
398 | 35 $hlBox = $(".js-paste-hl") |
442 | 36 return if $hlBox.attr("data-processed") == "1" |
398 | 37 |
38 $hlBox.text pasteText() | |
39 | |
40 highlight = -> hljs.highlightBlock($hlBox[0]) | |
41 setTimeout highlight, 0 | |
42 | |
442 | 43 $hlBox.attr "data-processed", "1" |
398 | 44 |
45 | |
442 | 46 markdownText = -> |
398 | 47 $mdBox = $(".js-paste-md") |
442 | 48 return if $mdBox.attr("data-processed") == "1" |
398 | 49 |
402 | 50 $mdBox.html markdownfy(pasteText()) |
398 | 51 $mdBox.find("a").attr("rel", "nofollow") |
442 | 52 $mdBox.attr "data-processed", "1" |
398 | 53 |
402 | 54 |
442 | 55 setHash = (e) -> |
56 return unless history.replaceState | |
57 | |
58 newLocation = "##{e.currentTarget.getAttribute("data-mode")}" | |
59 if newLocation == "#pl" | |
60 newLocation = window.location.pathname | |
61 | |
62 history.replaceState null, "", newLocation | |
63 | |
64 | |
65 showPreview = (e) -> | |
405
26c1b0b8edbe
Don't add hash when clicking preview.
nanaya <me@myconan.net>
parents:
404
diff
changeset
|
66 e.preventDefault() |
402 | 67 return if pasteText() == "" |
68 $(".js-paste-preview-md-box").html markdownfy(pasteText()) | |
69 $(".js-paste-preview-md-modal").modal "show" | |
70 | |
71 | |
442 | 72 switchToCurrentHash = -> |
416 | 73 return unless $(".js-showing-paste").length |
398 | 74 |
75 format = window.location.hash.slice(1) | |
442 | 76 $(".js-show-tab[data-mode=#{format}]").click() |
417
080dd141898c
Add support for explicit highlighter languages
nanaya <me@myconan.net>
parents:
416
diff
changeset
|
77 |
080dd141898c
Add support for explicit highlighter languages
nanaya <me@myconan.net>
parents:
416
diff
changeset
|
78 |
442 | 79 $ loadLanguageItems |
80 $ switchToCurrentHash | |
81 $(document).on "click", ".js-paste-preview-md", showPreview | |
82 $(document).on "click", ".js-show-tab[data-mode=hl]", highlightText | |
83 $(document).on "click", ".js-show-tab[data-mode=md]", markdownText | |
84 $(document).on "click", ".js-show-tab", setHash |