forked from linuxfrorg/linuxfr.org
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplication.coffee
More file actions
124 lines (109 loc) · 3.97 KB
/
application.coffee
File metadata and controls
124 lines (109 loc) · 3.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#= require jquery2
#= require jquery_ujs
#= require jquery.autocomplete
#= require jquery.caret-range
#= require jquery.cookie
#= require jquery.hotkeys
#= require jquery.notice
#= require jquery.markitup
#= require markitup-markdown
#= require_tree .
$ = window.jQuery
$("body").on "ajax:success", "form[data-remote]", (e, data) ->
$.noticeAdd text: data.notice if data and data.notice
$("#nb_votes").text data.nb_votes if data and data.nb_votes
$(@).parent().hide() unless $(@).data("hidden")
$(".markItUp").markItUp window.markItUpSettings
$("a.hit_counter[data-hit]").each ->
@href = "/redirect/" + $(@).data("hit")
# Ready to moule
$("input[autofocus=autofocus]").focus()
$(".board").chat()
$("#news_revisions").redaction()
# Force people to preview their modified contents
$("textarea, #form_answers input").keypress (event) ->
$(@).parents("form").find("input[value=Prévisualiser]").next("input[type=submit]").hide()
$(@).off event
# Add/Remove dynamically links in the news form
$("#form_links").nested_fields "news", "link", "lien", "fieldset", title: "text", url: "url", lang: window.langs
$("#form_answers").nested_fields "poll", "answer", "choix", "p", answer: "text"
# Mask the contributors if they are too many
$("article.news .edited_by").each ->
field = $(@)
nb = field.find("a").length
if nb > 3
was = field.html()
field.html "<a>#{nb} personnes</a>"
field.one "click", -> field.html was
# Toolbar preferences
$("#account_visible_toolbar")
.prop("checked", Toolbar.storage.visible != "false")
.click ->
Toolbar.storage.visible = $(@).is(":checked")
true
# Show the toolbar
$.fn.reverse = [].reverse
if $("body").hasClass("logged")
if $("#comments").length
$("#comments .new-comment")
.toolbar("Nouveaux commentaires", folding: "#comments .comment")
.additional $("#comments .comment").sort((a,b) -> a.id.localeCompare(b.id)), "Commentaires par ordre chronologique"
else if $("main .node").length
$("#phare .new-node, main .new-node:not(.ppp)")
.toolbar("Contenus jamais visités")
.additional $("#phare .new_comments, main .node:not(.ppp) .new_comments").parents("article").reverse(), "Contenus lus avec + de commentaires"
# Redaction
$(".edition_in_place").editionInPlace()
$("#redaction .new_link").editionInPlace()
$("#redaction .new_paragraph").on "ajax:success", false
$("#redaction .link, #redaction .paragraph").lockableEditionInPlace()
# Tags
$.fn.autocompleter = () ->
@each ->
input = $(@)
input.autocomplete input.data("url"),
multiple: true
multipleSeparator: " "
dataType: "text"
matchSubset: false
@
$("input#tags").autocompleter()
$(".tag_in_place").on("in_place:form", ->
$("input.autocomplete").autocompleter().focus()
).on("in_place:success", ->
$.noticeAdd text: "Étiquettes ajoutées"
).editionInPlace()
$(".add_tag, .remove_tag").click( ->
$(@).blur().parents("form").data hidden: "true"
).parents("form").on "ajax:success", ->
$(@).find("input").attr disabled: "disabled"
# Hotkeys
$(document).bind("keypress", "g", ->
$("html,body").animate scrollTop: 0, 500
false
).bind("keypress", "shift+g", ->
$("html,body").animate scrollTop: $("body").attr("scrollHeight"), 500
false
).bind "keypress", "shift+?", ->
$.noticeAdd
text: """
Raccourcis clavier : <ul>
<li>? pour l’aide</li>
<li>< pour le commentaire/contenu non lu précédent</li>
<li>> pour le commentaire/contenu non lu suivant</li>
<li>[ pour le contenu avec commentaire précédent</li>
<li>] pour le contenu avec commentaire suivant</li>
<li>g pour aller au début de la page</li>
<li>G pour aller à la fin de la page</li></ul>
"""
stay: true
false
$("#account_user_attributes_avatar").change ->
return if window.URL?
url = window.URL.createObjectURL(@files[0])
$(@).parents("form").find(".avatar").attr "src", url
# Follow-up, admins, plonk...
$("button.more").click ->
$(@).next('.more_actions').show()
$(@).hide()
false