-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a new better script for showing more/less
- Loading branch information
Showing
9 changed files
with
115 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@jsr:registry=https://npm.jsr.io |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import clip from "@arendjr/text-clipper"; | ||
|
||
/* | ||
This script adds a way to have a 'show more / show less' button | ||
on some text content. | ||
The usage is very simple, you just have to add the class `show-more` | ||
to the element you want to add the button to. | ||
Then, you can control the desired size by adding the attribute `show-size` | ||
to your element. | ||
This script does html matching and is able to properly cut rendered markdown. | ||
Example usage: | ||
<p class="show-more" show-size=20> | ||
My very long text will be cut by this script | ||
</p> | ||
*/ | ||
|
||
function showMore(element: HTMLElement) { | ||
if (!element.hasAttribute("show-size")) { | ||
return; | ||
} | ||
const fullContent = element.innerHTML; | ||
const clippedContent = clip( | ||
element.innerHTML, | ||
Number.parseInt(element.getAttribute("show-size") as string), | ||
{ | ||
html: true, | ||
}, | ||
); | ||
|
||
// If already at the desired size, we don't do anything | ||
if (clippedContent === fullContent) { | ||
return; | ||
} | ||
|
||
const actionLink = document.createElement("a"); | ||
|
||
let opened = false; | ||
|
||
const setText = () => { | ||
if (opened) { | ||
element.innerHTML = fullContent; | ||
actionLink.innerText = gettext("Show less"); | ||
} else { | ||
element.innerHTML = clippedContent; | ||
actionLink.innerText = gettext("Show more"); | ||
} | ||
element.appendChild(document.createElement("br")); | ||
element.appendChild(actionLink); | ||
}; | ||
|
||
const toggle = () => { | ||
opened = !opened; | ||
setText(); | ||
}; | ||
|
||
setText(); | ||
actionLink.addEventListener("click", (event) => { | ||
event.preventDefault(); | ||
toggle(); | ||
}); | ||
} | ||
|
||
document.addEventListener("DOMContentLoaded", () => { | ||
for (const elem of document.getElementsByClassName("show-more")) { | ||
showMore(elem as HTMLElement); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
msgid "" | ||
msgstr "" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2025-01-05 16:39+0100\n" | ||
"POT-Creation-Date: 2025-01-08 12:23+0100\n" | ||
"PO-Revision-Date: 2016-07-18\n" | ||
"Last-Translator: Maréchal <[email protected]\n" | ||
"Language-Team: AE info <[email protected]>\n" | ||
|
@@ -935,6 +935,12 @@ msgstr "rôle" | |
msgid "description" | ||
msgstr "description" | ||
|
||
#: club/models.py | ||
#, fuzzy | ||
#| msgid "Board member" | ||
msgid "past member" | ||
msgstr "Membre du bureau" | ||
|
||
#: club/models.py | ||
msgid "Email address" | ||
msgstr "Adresse email" | ||
|
@@ -3328,8 +3334,8 @@ msgstr "Nom d'utilisateur, email, ou numéro de compte AE" | |
|
||
#: core/views/forms.py | ||
msgid "" | ||
"Profile: you need to be visible on the picture, in order to be recognized (e." | ||
"g. by the barmen)" | ||
"Profile: you need to be visible on the picture, in order to be recognized " | ||
"(e.g. by the barmen)" | ||
msgstr "" | ||
"Photo de profil: vous devez être visible sur la photo afin d'être reconnu " | ||
"(par exemple par les barmen)" | ||
|
@@ -3935,8 +3941,8 @@ msgstr "" | |
#: counter/templates/counter/mails/account_dump.jinja | ||
msgid "If you think this was a mistake, please mail us at [email protected]." | ||
msgstr "" | ||
"Si vous pensez qu'il s'agit d'une erreur, veuillez envoyer un mail à ae@utbm." | ||
"fr." | ||
"Si vous pensez qu'il s'agit d'une erreur, veuillez envoyer un mail à " | ||
"ae@utbm.fr." | ||
|
||
#: counter/templates/counter/mails/account_dump.jinja | ||
msgid "" | ||
|
@@ -4456,14 +4462,6 @@ msgstr "Ajouter un nouveau rôle" | |
msgid "Submit the vote !" | ||
msgstr "Envoyer le vote !" | ||
|
||
#: election/templates/election/election_detail.jinja | ||
msgid "Show more" | ||
msgstr "Montrer plus" | ||
|
||
#: election/templates/election/election_detail.jinja | ||
msgid "Show less" | ||
msgstr "Montrer moins" | ||
|
||
#: election/templates/election/election_list.jinja | ||
msgid "Election list" | ||
msgstr "Liste des élections" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
msgid "" | ||
msgstr "" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2025-01-04 23:07+0100\n" | ||
"POT-Creation-Date: 2025-01-08 12:23+0100\n" | ||
"PO-Revision-Date: 2024-09-17 11:54+0200\n" | ||
"Last-Translator: Sli <[email protected]>\n" | ||
"Language-Team: AE info <[email protected]>\n" | ||
|
@@ -113,6 +113,14 @@ msgstr "Guide markdown" | |
msgid "Unsupported NFC card" | ||
msgstr "Carte NFC non supportée" | ||
|
||
#: core/static/bundled/core/read-more-index.ts | ||
msgid "Show less" | ||
msgstr "Montrer moins" | ||
|
||
#: core/static/bundled/core/read-more-index.ts | ||
msgid "Show more" | ||
msgstr "Montrer plus" | ||
|
||
#: core/static/bundled/user/family-graph-index.js | ||
msgid "family_tree.%(extension)s" | ||
msgstr "arbre_genealogique.%(extension)s" | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters