Skip to content

Commit

Permalink
Copy link to share program to clipboard when program is shared. (hedy…
Browse files Browse the repository at this point in the history
  • Loading branch information
fpereiro authored Jun 14, 2021
1 parent e22d0dd commit d48fe42
Show file tree
Hide file tree
Showing 13 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion coursedata/texts/de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ Auth:
unsaved_changes: "Du hast ein nicht gespeichertes Programm. Möchtest du es verwerfen, ohne zu speichern?"
save_success: "Erfolgreich"
save_success_detail: "Programm erfolgreich gespeichert"
share_success_detail: "Program shared successfully"
share_success_detail: "Program shared successfully and share link copied to clipboard"
unshare_success_detail: "Program unshared successfully"
copy_clipboard: "Successfully copied to clipboard"
answer_question: "Du kannst das Programm erst ausführen, nachdem du die Frage beantwortet hast."
Expand Down
2 changes: 1 addition & 1 deletion coursedata/texts/el.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ Auth:
unsaved_changes: 'Έχεις ένα μη αποθηκευμένο πρόγραμμα. Θέλεις να αποχωρήσεις χωρίς να το αποθηκεύσεις;'
save_success: 'Επιτυχία'
save_success_detail: 'Το πρόγραμμα αποθηκεύτηκε επιτυχώς'
share_success_detail: "Program shared successfully"
share_success_detail: "Program shared successfully and share link copied to clipboard"
unshare_success_detail: "Program unshared successfully"
copy_clipboard: "Successfully copied to clipboard"
answer_question: 'Δεν μπορείς να εκτελέσεις το πρόγραμμα πριν να απαντήσεις την ερώτηση'
Expand Down
2 changes: 1 addition & 1 deletion coursedata/texts/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ Auth:
unsaved_changes: "You have an unsaved program. Do you want to leave without saving it?"
save_success: "Success"
save_success_detail: "Program saved successfully"
share_success_detail: "Program shared successfully"
share_success_detail: "Program shared successfully and share link copied to clipboard"
unshare_success_detail: "Program unshared successfully"
copy_clipboard: "Successfully copied to clipboard"
answer_question: "You can't run the program until you answer the question first"
Expand Down
2 changes: 1 addition & 1 deletion coursedata/texts/es.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ Auth:
unsaved_changes: "Tu programa no se ha salvado. ¿Deseas irte sin salvarlo?"
save_success: "Éxito"
save_success_detail: "Tu programa se ha salvado exitosamente"
share_success_detail: "Tu programa es ahora público"
share_success_detail: "Tu programa es ahora público! Se ha copiado un enlace para compartir al portapapeles"
unshare_success_detail: "Tu programa es ahora privado"
copy_clipboard: "Copiado al portapapeles"
answer_question: "No puedes ejecutar el programa hasta que hayas contestado la pregunta"
Expand Down
2 changes: 1 addition & 1 deletion coursedata/texts/fr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ Auth:
unsaved_changes: "Le programme en cours n'a pas été sauvegardé. Souhaites-tu vraiment quitter sans le sauvegarder ?"
save_success: "Succès"
save_success_detail: "Le programme a été sauvegardé avec succès"
share_success_detail: "Program shared successfully"
share_success_detail: "Program shared successfully and share link copied to clipboard"
unshare_success_detail: "Program unshared successfully"
copy_clipboard: "Successfully copied to clipboard"
answer_question: "Tu ne peux pas exécuter le programme avant d'avoir répondu à la question."
Expand Down
2 changes: 1 addition & 1 deletion coursedata/texts/hu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ Auth:
unsaved_changes: "Nem mentett programod van. El akarsz menni mentés nélkül?"
save_success: "Siker"
save_success_detail: "A programot sikeresen mentetted"
share_success_detail: "Program shared successfully"
share_success_detail: "Program shared successfully and share link copied to clipboard"
unshare_success_detail: "Program unshared successfully"
copy_clipboard: "Successfully copied to clipboard"
answer_question: "Addig nem futtathatod a programot, amíg nem válaszolsz a kérdésre "
Expand Down
2 changes: 1 addition & 1 deletion coursedata/texts/it.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ Auth:
unsaved_changes: "Hai un programma non salvato. Vuoi uscire senza salvare?"
save_success: "Successo"
save_success_detail: "Programma salvato con successo"
share_success_detail: "Program shared successfully"
share_success_detail: "Program shared successfully and share link copied to clipboard"
unshare_success_detail: "Program unshared successfully"
copy_clipboard: "Successfully copied to clipboard"
answer_question: "Non puoi eseguire il programma prima di rispondere alla domanda"
Expand Down
2 changes: 1 addition & 1 deletion coursedata/texts/nl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ Auth:
unsaved_changes: "Jouw programma is niet opgeslagen. Wil je weggaan zonder het op te slaan?"
save_success: "Gelukt!"
save_success_detail: "Je programma is opgeslagen"
share_success_detail: "Program shared successfully"
share_success_detail: "Program shared successfully and share link copied to clipboard"
unshare_success_detail: "Program unshared successfully"
copy_clipboard: "Successfully copied to clipboard"
answer_question: "Je kunt het programma pas uitvoeren als je de vraag hebt beantwoord."
Expand Down
2 changes: 1 addition & 1 deletion coursedata/texts/pt_br.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ Auth:
unsaved_changes: "You have an unsaved program. Do you want to leave without saving it?"
save_success: "Success"
save_success_detail: "Program saved successfully"
share_success_detail: "Program shared successfully"
share_success_detail: "Program shared successfully and share link copied to clipboard"
unshare_success_detail: "Program unshared successfully"
copy_clipboard: "Successfully copied to clipboard"
answer_question: "You can't run the program until you answer the question first"
Expand Down
2 changes: 1 addition & 1 deletion coursedata/texts/sw.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Auth:
unsaved_changes: "Una programu ambao haujahifadhiwa. Je! Unataka kuondoka bila kuiokoa?"
save_success: "Fanikio"
save_success_detail: "Programu imehifadhiwa kwa mafanikio"
share_success_detail: "Program shared successfully"
share_success_detail: "Program shared successfully and share link copied to clipboard"
unshare_success_detail: "Program unshared successfully"
copy_clipboard: "Successfully copied to clipboard"
answer_question: "Huwezi kuendesha programu hadi ujibu swali kwanza"
Expand Down
2 changes: 1 addition & 1 deletion coursedata/texts/zh.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ Auth:
unsaved_changes: "你有一个未保存的程序. 你想不保存就离开吗?"
save_success: "成功"
save_success_detail: "程序保存成功"
share_success_detail: "Program shared successfully"
share_success_detail: "Program shared successfully and share link copied to clipboard"
unshare_success_detail: "Program unshared successfully"
copy_clipboard: "Successfully copied to clipboard"
answer_question: "你要先回答问题,才能运行程序."
Expand Down
10 changes: 7 additions & 3 deletions static/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ window.saveit = function saveit(level, lang, name, code, cb) {
}
}

window.share_program = function share_program (id, Public, reload) {
window.share_program = function share_program (id, level, Public, reload) {
$.ajax({
type: 'POST',
url: '/programs/share',
Expand All @@ -265,8 +265,12 @@ window.share_program = function share_program (id, Public, reload) {
$ ('#okbox').show ();
$ ('#okbox .caption').html (window.auth.texts.save_success);
$ ('#okbox .details').html (Public ? window.auth.texts.share_success_detail : window.auth.texts.unshare_success_detail);
// If we're sharing the program, copy the link to the clipboard.
if (Public) window.copy_to_clipboard (window.location.origin + '/hedy/' + level + '/' + id, true);
}
else {
// If we're sharing the program, copy the link to the clipboard.
if (Public) window.copy_to_clipboard (window.location.origin + '/hedy/' + level + '/' + id, true);
alert (Public ? window.auth.texts.share_success_detail : window.auth.texts.unshare_success_detail);
}
if (reload) setTimeout (function () {location.reload ()}, 1000);
Expand All @@ -276,7 +280,7 @@ window.share_program = function share_program (id, Public, reload) {
});
}

window.copy_to_clipboard = function copy_to_clipboard (string) {
window.copy_to_clipboard = function copy_to_clipboard (string, noAlert) {
// https://hackernoon.com/copying-text-to-clipboard-with-javascript-df4d4988697f
var el = document.createElement ('textarea');
el.value = string;
Expand All @@ -292,7 +296,7 @@ window.copy_to_clipboard = function copy_to_clipboard (string) {
document.getSelection ().removeAllRanges ();
document.getSelection ().addRange (selected);
}
alert (window.auth.texts.copy_clipboard);
if (! noAlert) alert (window.auth.texts.copy_clipboard);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions templates/programs.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

<a href="#" onclick="if (confirm ('{{ texts.delete_confirm }}')) window.open ('/programs/delete/{{program.id}}', '_self')">{{ texts.delete }}</a>
{% if program.public %}
<a href="#" onclick="if (confirm ('{{ texts.unshare_confirm }}')) window.share_program ('{{program.id}}', false, true)">{{ texts.unshare}}</a>
<a href="#" onclick="if (confirm ('{{ texts.unshare_confirm }}')) window.share_program ('{{program.id}}', {{program.level}}, false, true)">{{ texts.unshare}}</a>
<a href="#" onclick="window.copy_to_clipboard (window.location.origin + '{{'/hedy/' + program.level|string + '/' + program.id}}')">{{ texts.copy_link_to_share }}</a>
{% else %}
<a href="#" onclick="if (confirm ('{{ texts.share_confirm }}')) window.share_program ('{{program.id}}', true, true)">{{ texts.share}}</a>
<a href="#" onclick="if (confirm ('{{ texts.share_confirm }}')) window.share_program ('{{program.id}}', {{program.level}}, true, true)">{{ texts.share}}</a>
{% endif %}
<pre>{{program.code | truncate (50) }}</pre>
</li>
Expand Down

0 comments on commit d48fe42

Please sign in to comment.