-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JS Cleanup #198
base: development
Are you sure you want to change the base?
JS Cleanup #198
Changes from 9 commits
aa023c4
936188a
d29ac36
fa048d1
b07de69
1ddeff4
19c7cf9
29acddd
5a02438
8b55e90
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,3 @@ | ||
<script> | ||
function showDiv(name) { | ||
document.getElementById('edit').style.display = "block"; | ||
document.getElementById('id_cree').focus() | ||
|
||
const translation = document.getElementById(name + '-translation').innerHTML; | ||
|
||
document.getElementById('id_cree').value = name; | ||
document.getElementById('id_translation').value = translation; | ||
} | ||
|
||
function showDivAccept(name, translation, analysis) { | ||
document.getElementById('edit').style.display = "block"; | ||
document.getElementById('id_cree').focus() | ||
|
||
document.getElementById('id_cree').value = name; | ||
document.getElementById('id_translation').value = translation; | ||
document.getElementById('id_analysis').value = analysis; | ||
} | ||
|
||
function hideDiv() { | ||
document.getElementById('edit').style.display = "none"; | ||
} | ||
|
||
function revert(transcription, translation, analysis) { | ||
document.getElementById('edit').style.display = "block"; | ||
document.getElementById('id_cree').focus() | ||
|
||
document.getElementById('id_cree').value = transcription; | ||
document.getElementById('id_translation').value = translation; | ||
document.getElementById('id_analysis').value = analysis; | ||
} | ||
|
||
function goBack() { | ||
window.history.back() | ||
} | ||
|
||
|
||
</script> | ||
|
||
{% extends 'validation/_base.html' %} | ||
{% import 'validation/_macros.html' as macros %} | ||
|
@@ -45,11 +6,13 @@ | |
<div class="table-responsive"> | ||
|
||
<div> | ||
<button class="button button--success button--back" onclick='goBack()'>Back</button> | ||
<button data-cy="back-button" class="button button--success button--back">Back</button> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a really pendatic note, but this should be an // adapted from: https://stackoverflow.com/a/46163215/6626414
for (let el of document.querySelectorAll('a.button--back')) {
el.setAttribute('href', document.referrer);
// this remains the same!
el.addEventListener('click', (evt) => {
window.history.back();
})
} |
||
{% if auth %} | ||
<button data-cy="edit-button" class="button button--fail button--right button--edit" | ||
onclick="showDiv('{{ segment_name }}')" | ||
class="button button--fail button--right"> | ||
<button | ||
data-cy="edit-button" | ||
data-segment-name="{{ segment_name }}" | ||
class="button button--fail button--right button--edit" | ||
> | ||
Edit | ||
</button> | ||
{% endif %} | ||
|
@@ -123,7 +86,14 @@ | |
<td> | ||
{% set transl = suggestions[suggestion]["matches"][0]["translations"] %} | ||
{% set analysis = suggestions[suggestion]["matches"][0]["analysis"] %} | ||
<input type="button" class="button button--success" value="Accept" onclick="showDivAccept('{{ suggestion }}', '{{ transl }}', '{{ analysis }}')" /> | ||
<input | ||
type="button" | ||
data-cy="accept-button" | ||
class="button button--success" | ||
value="Accept" | ||
data-transcription="{{ suggestion }}" | ||
data-translation="{{ transl }}" | ||
data-analysis="{{ analysis }}" /> | ||
</td> | ||
{% endif %} | ||
{% endif %} | ||
|
@@ -137,7 +107,14 @@ | |
<td> | ||
{% set transl = match["translations"] %} | ||
{% set analysis = match["analysis"] %} | ||
<input type="button" class="button button--success" value="Accept" onclick="showDivAccept('{{ suggestion }}', '{{ transl }}', '{{ analysis }}')" /> | ||
<input | ||
type="button" | ||
class="button button--success" | ||
value="Accept" | ||
data-cy="accept-button" | ||
data-transcription="{{ suggestion }}" | ||
data-translation="{{ transl }}" | ||
data-analysis="{{ analysis }}"/> | ||
</td> | ||
</tr> | ||
{% endif %} | ||
|
@@ -168,7 +145,15 @@ <h4>Revision History:</h4> | |
<td data-cy="revision-analysis">{{ revision.analysis }} </td> | ||
{% if auth %} | ||
<td> | ||
<input type="button" class="button button--fail" value="Revert" onclick="revert('{{ revision.transcription }}', '{{ revision.translation }}', '{{ revision.analysis }}')" /> | ||
<input | ||
type="button" | ||
class="button button--fail" | ||
value="Revert" | ||
data-cy="revert-button" | ||
data-transcription="{{ revision.transcription }}" | ||
data-translation="{{ revision.translation }}" | ||
data-analysis="{{ revision.analysis }}" | ||
/> | ||
</td> | ||
{% endif %} | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -4,6 +4,6 @@ <h5>Edit Segment</h5> | |||||
<input type="hidden" name="csrfmiddlewaretoken" value="{{ csrf_token }}"> | ||||||
{{ form }} | ||||||
<input data-cy="save-button" type="submit" class="button button--success" value="Save"> | ||||||
<input data-cy="cancel-button" type="button" class="button button--fail" onclick="hideDiv()" value="Cancel"> | ||||||
<input data-cy="cancel-button" type="button" class="button button--fail" value="Cancel"> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be a
Suggested change
|
||||||
</form> | ||||||
</div> | ||||||
</div> |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,46 @@ | ||||||||||
"use strict"; | ||||||||||
|
||||||||||
document.addEventListener('DOMContentLoaded', () => { | ||||||||||
for (let button of document.querySelectorAll('[data-segment-name]')) { | ||||||||||
button.addEventListener("click", async (e) => { | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
showDiv() | ||||||||||
const name = e.target.dataset.segmentName | ||||||||||
const translation = document.getElementById(name + '-translation').innerHTML; | ||||||||||
|
||||||||||
document.getElementById('id_cree').value = name; | ||||||||||
document.getElementById('id_translation').value = translation; | ||||||||||
}) | ||||||||||
} | ||||||||||
|
||||||||||
for (let button of document.querySelectorAll('[data-cy="accept-button"], [data-cy="revert-button"]')) { | ||||||||||
button.addEventListener("click", async(e) => { | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
showDiv() | ||||||||||
|
||||||||||
const transcription = e.target.dataset.transcription | ||||||||||
const translation = e.target.dataset.translation | ||||||||||
const analysis = e.target.dataset.analysis | ||||||||||
Comment on lines
+19
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you want to use some fancier syntax*
Suggested change
*I think this has now has excellent browser support |
||||||||||
|
||||||||||
document.getElementById('id_cree').value = transcription; | ||||||||||
document.getElementById('id_translation').value = translation; | ||||||||||
document.getElementById('id_analysis').value = analysis; | ||||||||||
}) | ||||||||||
} | ||||||||||
|
||||||||||
for (let button of document.querySelectorAll('[data-cy="cancel-button"]')) { | ||||||||||
button.addEventListener("click", async(e) => { | ||||||||||
document.getElementById('edit').style.display = "none"; | ||||||||||
}) | ||||||||||
} | ||||||||||
|
||||||||||
for (let button of document.querySelectorAll('[data-cy="back-button"]')) { | ||||||||||
button.addEventListener("click", async(e) => { | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
window.history.back() | ||||||||||
}) | ||||||||||
} | ||||||||||
}) | ||||||||||
|
||||||||||
|
||||||||||
function showDiv() { | ||||||||||
document.getElementById('edit').style.display = "block"; | ||||||||||
document.getElementById('id_cree').focus() | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: assigning focus programmatically is considered not a great practice, but here, I don't think it matters much. Always be careful with focus stealing. |
||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
"use strict"; | ||
|
||
// Helper functions that are needed across multiple JS files | ||
|
||
|
||
function getElementByPhraseId(className, phraseId) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should be able to do a lookup using the DOM API instead of having to do a linear scan:
That said, I know there were issues with quoting related to the format of the ID that may make that trickier. That’s one reason that automatic numeric ID columns are so handy. |
||
const elements = document.getElementsByClassName(className); | ||
for (let e of elements) { | ||
if (e.dataset.phraseId === phraseId) { | ||
return e | ||
} | ||
} | ||
} | ||
|
||
function getElementByRecordingId(className, recordingId) { | ||
const elements = document.getElementsByClassName(className); | ||
for (let e of elements) { | ||
if (e.dataset.recId === recordingId) { | ||
return e | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,21 @@ | ||
"use strict"; | ||
|
||
function showMenu() { | ||
let menu = document.getElementById("options-menu"); | ||
if (menu.classList.contains("menu__none")) { | ||
menu.classList.remove("menu__none"); | ||
menu.classList.add("menu__block"); | ||
} else { | ||
menu.classList.add("menu__none"); | ||
menu.classList.remove("menu__block"); | ||
document.addEventListener("DOMContentLoaded", () => { | ||
for (let link of document.querySelectorAll('[data-cy="show-flex-button"]')) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So "flex" button refefers to 'flex as in "cirum" and not as in "-box". Because I thought this was a like a |
||
link.addEventListener("click", () => { | ||
showCircumflex("on"); | ||
}) | ||
} | ||
} | ||
|
||
function showMacron(option) { | ||
for (let link of document.querySelectorAll('[data-cy="no-flex-button"]')) { | ||
link.addEventListener("click", () => { | ||
showCircumflex("off"); | ||
}) | ||
} | ||
}) | ||
|
||
|
||
function showCircumflex(option) { | ||
document.cookie = "macron=" + option + "; SameSite=Lax;" | ||
let menu = document.getElementById("options-menu"); | ||
menu.classList.add("menu__none"); | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,28 @@ | ||||||
"use strict"; | ||||||
|
||||||
document.addEventListener("DOMContentLoaded", () => { | ||||||
for (let button of document.querySelectorAll('[data-cy="wrong-word-button"]')) { | ||||||
button.addEventListener("click", async (e) => { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
const recordingId = e.target.dataset.recId; | ||||||
showWrongWordDiv(recordingId); | ||||||
}) | ||||||
} | ||||||
|
||||||
for (let button of document.querySelectorAll('[data-cy="cancel-wrong-word-button"]')) { | ||||||
button.addEventListener("click", async (e) => { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
const recordingId = e.target.dataset.recId; | ||||||
hideWrongWordDiv(recordingId); | ||||||
}) | ||||||
} | ||||||
}); | ||||||
|
||||||
|
||||||
function showWrongWordDiv(recordingId) { | ||||||
const wrongWordDiv = getElementByRecordingId("rec-wrong-word", recordingId); | ||||||
wrongWordDiv.classList.replace("menu__none", "menu__block"); | ||||||
} | ||||||
|
||||||
function hideWrongWordDiv(recordingId) { | ||||||
const wrongWordDiv = getElementByRecordingId("rec-wrong-word", recordingId); | ||||||
wrongWordDiv.classList.replace("menu__block", "menu__none"); | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be a
<button>
?