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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
2 #= require bootstrap
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
3 #= require highlightjs
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
4 #= require commonmark
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
5
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
6 $(document).on "click", ".js-paste-clear", (e) ->
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
7 e.preventDefault()
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
8 $(".js-paste-paste")
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
9 .val("")
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
10 .focus()
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
11
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
12
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
13 pasteText = ->
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
14 $(".js-paste-pl").text()
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
15
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
16
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
17 setHash = (newLocation = window.location.pathname) ->
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
18 return unless history.replaceState
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
19
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
20 newLocation ||= window.location.pathname
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
21 history.replaceState null, "", newLocation
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
22
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
23
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
24 $(document).on "click", ".js-show-tab-pl", ->
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
25 setHash()
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
26
382
8ceb373e32d8 Nuke out javascripts =]
nanaya <me@myconan.net>
parents: 381
diff changeset
27
398
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
28 $(document).on "click", ".js-show-tab-hl", ->
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
29 setHash "#hl"
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
30 $hlBox = $(".js-paste-hl")
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
31 return if $hlBox.data("processed")
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
32
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
33 $hlBox.text pasteText()
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
34
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
35 highlight = -> hljs.highlightBlock($hlBox[0])
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
36 setTimeout highlight, 0
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
37
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
38 $hlBox.data "processed", true
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
39
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
40
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
41 $(document).on "click", ".js-show-tab-md", ->
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
42 setHash "#md"
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
43 $mdBox = $(".js-paste-md")
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
44 return if $mdBox.data("processed")
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
45
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
46 reader = new commonmark.Parser
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
47 writer = new commonmark.HtmlRenderer(safe: true)
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
48 parsed = reader.parse pasteText()
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
49
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
50 $mdBox.html writer.render(parsed)
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
51 $mdBox.find("a").attr("rel", "nofollow")
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
52 $mdBox.data "processed", true
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
53
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
54 $(document).on "ready", ->
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
55 return if $(".js-showing-paste").length < 1
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
56
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
57 format = window.location.hash.slice(1)
851432f21603 Nope, failing at redesigning.
nanaya <me@myconan.net>
parents: 382
diff changeset
58 $(".js-show-tab-#{format}").click()