Make IPA fields use KeyboardFire/phondue

This commit is contained in:
Robbie Antenesse 2019-05-09 13:55:49 -06:00
parent 2a35439c3f
commit fdd12983ff
6 changed files with 53 additions and 20 deletions

View File

@ -80,7 +80,7 @@
<input id="wordName"> <input id="wordName">
</label> </label>
<label>Pronunciation<a class="label-button ipa-table-button">IPA Chart</a><br> <label>Pronunciation<a class="label-button ipa-table-button">IPA Chart</a><br>
<input id="wordPronunciation"><br> <input id="wordPronunciation" class="ipa-field"><br>
<a class="label-help-button ipa-field-help-button">Field Help</a> <a class="label-help-button ipa-field-help-button">Field Help</a>
</label> </label>
<label>Part of Speech<br> <label>Part of Speech<br>
@ -203,21 +203,21 @@
<div class="split three"> <div class="split three">
<div> <div>
<label>Consonants<br> <label>Consonants<br>
<input id="editConsonants"><br> <input id="editConsonants" class="ipa-field"><br>
<a class="label-help-button ipa-field-help-button">Field Help</a> <a class="label-help-button ipa-field-help-button">Field Help</a>
<a class="label-button ipa-table-button">IPA Chart</a> <a class="label-button ipa-table-button">IPA Chart</a>
</label> </label>
</div> </div>
<div> <div>
<label>Vowels<br> <label>Vowels<br>
<input id="editVowels"><br> <input id="editVowels" class="ipa-field"><br>
<a class="label-help-button ipa-field-help-button">Field Help</a> <a class="label-help-button ipa-field-help-button">Field Help</a>
<a class="label-button ipa-table-button">IPA Chart</a> <a class="label-button ipa-table-button">IPA Chart</a>
</label> </label>
</div> </div>
<div> <div>
<label>Polyphthongs&nbsp;/ Blends<br> <label>Polyphthongs&nbsp;/ Blends<br>
<input id="editBlends"><br> <input id="editBlends" class="ipa-field"><br>
<a class="label-help-button ipa-field-help-button">Field Help</a> <a class="label-help-button ipa-field-help-button">Field Help</a>
<a class="label-button ipa-table-button">IPA Chart</a> <a class="label-button ipa-table-button">IPA Chart</a>
</label> </label>

View File

@ -0,0 +1,15 @@
import digraphs from './digraphs.json';
import { setSelectionRange, insertAtCursor } from '../../StackOverflow/inputCursorManagement.js';
export function usePhondueDigraphs(event) {
let val = event.target.value;
let pos = event.target.selectionStart || val.length;
const key = typeof event.which !== "undefined" ? event.which : event.keyCode,
digraph = digraphs[val.substr(pos - 1, 1) + String.fromCharCode(key)];
if (digraph) {
event.preventDefault();
insertAtCursor(event.target, digraph, -1);
}
}

View File

@ -1,4 +1,4 @@
export function insertAtCursor(myField, myValue) { export function insertAtCursor(myField, myValue, adjustStart = 0) {
// http://stackoverflow.com/questions/11076975/insert-text-into-textarea-at-cursor-position-javascript // http://stackoverflow.com/questions/11076975/insert-text-into-textarea-at-cursor-position-javascript
// IE support // IE support
if (document.selection) { if (document.selection) {
@ -9,6 +9,7 @@ export function insertAtCursor(myField, myValue) {
// MOZILLA and others // MOZILLA and others
else if (myField.selectionStart || myField.selectionStart == '0') { else if (myField.selectionStart || myField.selectionStart == '0') {
const selection = getInputSelection(myField); const selection = getInputSelection(myField);
selection.start += adjustStart;
myField.value = myField.value.substring(0, selection.start) myField.value = myField.value.substring(0, selection.start)
+ myValue + myValue
+ myField.value.substring(selection.end, myField.value.length); + myField.value.substring(selection.end, myField.value.length);

View File

@ -11,7 +11,8 @@ import {
setupWordEditFormButtons, setupWordEditFormButtons,
setupMaximizeModal, setupMaximizeModal,
setupInfoModal, setupInfoModal,
setupIPATable setupIPATable,
setupIPAFields
} from './setupListeners'; } from './setupListeners';
import { getPaginationData } from './pagination'; import { getPaginationData } from './pagination';
import { getOpenEditForms } from './wordManagement'; import { getOpenEditForms } from './wordManagement';
@ -269,7 +270,7 @@ export function renderIPATable(ipaTableButton) {
modalElement.innerHTML = `<div class="modal-background"></div> modalElement.innerHTML = `<div class="modal-background"></div>
<div class="modal-content"> <div class="modal-content">
<a class="close-button">&times;&#xFE0E;</a> <a class="close-button">&times;&#xFE0E;</a>
<header><label>Pronunciation <input value="${textBox.value}"></label></header> <header><label>Pronunciation <input value="${textBox.value}" class="ipa-field"></label></header>
<section> <section>
${html} ${html}
</section> </section>
@ -278,6 +279,7 @@ export function renderIPATable(ipaTableButton) {
document.body.appendChild(modalElement); document.body.appendChild(modalElement);
setupIPAFields();
setupIPATable(modalElement, textBox); setupIPATable(modalElement, textBox);
}); });
} }
@ -305,8 +307,8 @@ export function renderMaximizedTextbox(maximizeButton) {
export function renderInfoModal(content) { export function renderInfoModal(content) {
const modalElement = document.createElement('section'); const modalElement = document.createElement('section');
modalElement.classList.add('modal'); modalElement.classList.add('modal', 'info-modal');
modalElement.innerHTML = `<section class="modal maximize-modal"><div class="modal-background"></div> modalElement.innerHTML = `<div class="modal-background"></div>
<div class="modal-content"> <div class="modal-content">
<a class="close-button">&times;&#xFE0E;</a> <a class="close-button">&times;&#xFE0E;</a>
<section class="info-modal"> <section class="info-modal">
@ -314,8 +316,7 @@ export function renderInfoModal(content) {
${content} ${content}
</div> </div>
</section> </section>
</div> </div>`;
</section>`;
document.body.appendChild(modalElement); document.body.appendChild(modalElement);

View File

@ -6,6 +6,7 @@ import { getNextId } from './utilities';
import { openEditModal, saveEditModal, saveAndCloseEditModal } from './dictionaryManagement'; import { openEditModal, saveEditModal, saveAndCloseEditModal } from './dictionaryManagement';
import { goToNextPage, goToPreviousPage, goToPage } from './pagination'; import { goToNextPage, goToPreviousPage, goToPage } from './pagination';
import { insertAtCursor } from './StackOverflow/inputCursorManagement'; import { insertAtCursor } from './StackOverflow/inputCursorManagement';
import { usePhondueDigraphs } from './KeyboardFire/phondue/ipaField';
export default function setupListeners() { export default function setupListeners() {
setupDetailsTabs(); setupDetailsTabs();
@ -164,7 +165,7 @@ function setupWordForm() {
} }
}); });
setupIPAButtons(); setupIPAFields();
setupMaximizeButtons(); setupMaximizeButtons();
} }
@ -228,7 +229,7 @@ export function setupWordEditFormButtons() {
button.addEventListener('click', cancelEditWord); button.addEventListener('click', cancelEditWord);
}); });
setupIPAButtons(); setupIPAFields();
setupMaximizeButtons(); setupMaximizeButtons();
} }
@ -267,6 +268,16 @@ export function setupPagination() {
}); });
} }
export function setupIPAFields() {
const ipaFields = document.getElementsByClassName('ipa-field');
Array.from(ipaFields).forEach(field => {
field.removeEventListener('keypress', usePhondueDigraphs);
field.addEventListener('keypress', usePhondueDigraphs);
});
setupIPAButtons();
}
export function setupIPAButtons() { export function setupIPAButtons() {
const ipaTableButtons = document.getElementsByClassName('ipa-table-button'), const ipaTableButtons = document.getElementsByClassName('ipa-table-button'),
ipaFieldHelpButtons = document.getElementsByClassName('ipa-field-help-button'); ipaFieldHelpButtons = document.getElementsByClassName('ipa-field-help-button');

View File

@ -22,6 +22,11 @@ label {
font-weight: normal; font-weight: normal;
} }
input:not([type="checkbox"]):not([type="radio"]) {
padding-bottom: 2px;
line-height: 130%;
}
input:not([type="checkbox"]):not([type="radio"]), input:not([type="checkbox"]):not([type="radio"]),
select, textarea { select, textarea {
font-weight: normal; font-weight: normal;