Skip to content

Commit 819532c

Browse files
nudTrim
authored andcommitted
Remove CoffeeScript, use plain Javascript instead
CoffeeScript is (mostly) dead these days and, while it was advertised with Rails 5 and older, it is not supported anymore by newer version of Rails. Using plain Javascript might also make it easier for new contributors to fix issues as nobody is familiar with CoffeeScript these days. In this commit we run `decaffeinate` on all the `.coffee` files and nothing else. See https://decaffeinate-project.org/ Suivi #3034
1 parent ee3ba80 commit 819532c

23 files changed

+1378
-800
lines changed

app/assets/javascripts/application.coffee

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

0 commit comments

Comments
 (0)