Skip to content

Commit 0f64161

Browse files
committed
Merge branch 'decaffeinate' of https://github.com/nud/linuxfr.org into rails7
2 parents 2a1b66f + 4fd42e0 commit 0f64161

23 files changed

+1290
-800
lines changed

app/assets/javascripts/application.coffee

Lines changed: 0 additions & 148 deletions
This file was deleted.
Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
//= require jquery2
2+
//= require jquery_ujs
3+
//= require jquery.autocomplete
4+
//= require jquery.caret-range
5+
//= require jquery.cookie
6+
//= require jquery.hotkeys
7+
//= require jquery.notice
8+
//= require jquery.markitup
9+
//= require markitup-markdown
10+
//= require_tree .
11+
12+
$ = window.jQuery;
13+
14+
$("body").on("ajax:success", "form[data-remote]", function(e, data) {
15+
if (data && data.notice) {
16+
$.noticeAdd({ text: data.notice });
17+
}
18+
if (data && data.nb_votes) {
19+
$("#nb_votes").text(data.nb_votes);
20+
}
21+
if (!$(this).data("hidden")) {
22+
$(this)
23+
.parent()
24+
.hide();
25+
}
26+
});
27+
28+
$(".markItUp").markItUp(window.markItUpSettings);
29+
30+
$("a.hit_counter[data-hit]").each(function() {
31+
this.href = "/redirect/" + $(this).data("hit");
32+
});
33+
34+
// Ready to moule
35+
$("input[autofocus=autofocus]").focus();
36+
$(".board").chat();
37+
$("#news_revisions").redaction();
38+
39+
// Force people to preview their modified contents
40+
$("textarea, #form_answers input").keypress(function(event) {
41+
$(this)
42+
.parents("form")
43+
.find("input[value=Prévisualiser]")
44+
.next("input[type=submit]")
45+
.hide();
46+
$(this).off(event);
47+
});
48+
49+
// Add/Remove dynamically links in the news form
50+
const langs = {
51+
xx: "!? hmmm ?!",
52+
fr: "Français",
53+
de: "Allemand",
54+
en: "Anglais",
55+
eu: "Basque",
56+
ct: "Catalan",
57+
cn: "Chinois",
58+
wq: "Code/binaire",
59+
ko: "Coréen",
60+
da: "Danois",
61+
es: "Espagnol",
62+
ee: "Estonien",
63+
fi: "Finnois",
64+
el: "Grec",
65+
it: "Italien",
66+
ja: "Japonais",
67+
nl: "Néerlandais",
68+
no: "Norvégien",
69+
pl: "Polonais",
70+
pt: "Portugais",
71+
ru: "Russe",
72+
sv: "Suédois"
73+
};
74+
75+
$("#form_links").nested_fields("news", "link", "lien", "fieldset", {
76+
title: "text",
77+
url: "url",
78+
lang: langs
79+
});
80+
$("#form_answers").nested_fields("poll", "answer", "choix", "p", {
81+
answer: "text"
82+
});
83+
84+
// Mask the contributors if they are too many
85+
$("article.news .edited_by").each(function() {
86+
const field = $(this);
87+
const nb = field.find("a").length;
88+
if (nb > 3) {
89+
const was = field.html();
90+
field.html(`<a>${nb} personnes</a>`);
91+
field.one("click", () => field.html(was));
92+
}
93+
});
94+
95+
// Toolbar preferences
96+
$("#account_visible_toolbar")
97+
.prop("checked", Toolbar.storage.visible !== "false")
98+
.click(function() {
99+
Toolbar.storage.visible = $(this).is(":checked");
100+
return true;
101+
});
102+
103+
// Show the toolbar
104+
$.fn.reverse = [].reverse;
105+
if ($("body").hasClass("logged")) {
106+
if ($("#comments").length) {
107+
$("#comments .new-comment")
108+
.toolbar("Nouveaux commentaires", { folding: "#comments .comment" })
109+
.additional(
110+
$("#comments .comment").sort((a, b) => a.id.localeCompare(b.id)),
111+
"Commentaires par ordre chronologique"
112+
);
113+
} else if ($("main .node").length) {
114+
$("#phare .new-node, main .new-node:not(.ppp)")
115+
.toolbar("Contenus jamais visités")
116+
.additional(
117+
$("#phare .new_comments, main .node:not(.ppp) .new_comments")
118+
.parents("article")
119+
.reverse(),
120+
"Contenus lus avec + de commentaires"
121+
);
122+
}
123+
}
124+
125+
// Redaction
126+
$(".edition_in_place").editionInPlace();
127+
$("#redaction .new_link").editionInPlace();
128+
$("#redaction .new_paragraph").on("ajax:success", false);
129+
$("#redaction .link, #redaction .paragraph").lockableEditionInPlace();
130+
131+
// Tags
132+
$.fn.autocompleter = function() {
133+
return this.each(function() {
134+
const input = $(this);
135+
return input.autocomplete(input.data("url"), {
136+
multiple: true,
137+
multipleSeparator: " ",
138+
dataType: "text",
139+
matchSubset: false
140+
});
141+
});
142+
return this;
143+
};
144+
$("input#tags").autocompleter();
145+
$(".tag_in_place")
146+
.on("in_place:form", () =>
147+
$("input.autocomplete")
148+
.autocompleter()
149+
.focus()
150+
)
151+
.on("in_place:success", () => $.noticeAdd({ text: "Étiquettes ajoutées" }))
152+
.editionInPlace();
153+
$(".add_tag, .remove_tag")
154+
.click(function() {
155+
$(this)
156+
.blur()
157+
.parents("form")
158+
.data({ hidden: "true" });
159+
})
160+
.parents("form")
161+
.on("ajax:success", function() {
162+
$(this)
163+
.find("input")
164+
.attr({ disabled: "disabled" });
165+
});
166+
167+
// Hotkeys
168+
$(document)
169+
.bind("keypress", "g", function() {
170+
$("html,body").animate({ scrollTop: 0 }, 500);
171+
return false;
172+
})
173+
.bind("keypress", "shift+g", function() {
174+
$("html,body").animate({ scrollTop: document.body.offsetHeight }, 500);
175+
return false;
176+
})
177+
.bind("keypress", "shift+?", function() {
178+
$.noticeAdd({
179+
text: `\
180+
Raccourcis clavier : <ul>
181+
<li>? pour l’aide</li>
182+
<li>&lt; pour le commentaire/contenu non lu précédent</li>
183+
<li>&gt; pour le commentaire/contenu non lu suivant</li>
184+
<li>[ pour le contenu avec commentaire précédent</li>
185+
<li>] pour le contenu avec commentaire suivant</li>
186+
<li>g pour aller au début de la page</li>
187+
<li>G pour aller à la fin de la page</li></ul>\
188+
`,
189+
stay: true
190+
});
191+
return false;
192+
});
193+
194+
$("#account_user_attributes_avatar").change(function() {
195+
if (!window.URL) {
196+
return;
197+
}
198+
const url = window.URL.createObjectURL(this.files[0]);
199+
return $(this)
200+
.parents("form")
201+
.find(".avatar")
202+
.attr("src", url);
203+
});
204+
205+
// Follow-up, admins, plonk...
206+
$("button.more").click(function() {
207+
$(this)
208+
.next(".more_actions")
209+
.show();
210+
$(this).hide();
211+
});

0 commit comments

Comments
 (0)