Skip to content

Commit

Permalink
Add untoggle invalid obliques MEI Action
Browse files Browse the repository at this point in the history
  • Loading branch information
yinanazhou committed Feb 7, 2024
1 parent a0abe17 commit 399fa98
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions assets/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<div id="remove-empty-syls" class="navbar-dropdown-item">Remove Empty Syllables</div>
<div id="remove-empty-neumes" class="navbar-dropdown-item">Remove Empty Neumes</div>
<div id="remove-out-of-bounds-glyphs" class="navbar-dropdown-item">Remove Out-of-bounds Glyphs</div>
<div id="untoggle-invalid-oblique" class="navbar-dropdown-item">Untoggle Invalid Obliques</div>
<div id="untoggle-invalid-syls" class="navbar-dropdown-item">Untoggle Invalid Toggled Syllables</div>
<div id="revert" class="navbar-dropdown-item">Revert</div>
</div>
Expand Down
53 changes: 53 additions & 0 deletions src/utils/EditControls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,59 @@ export function initNavbar (neonView: NeonView): void {
});
});

document.getElementById('untoggle-invalid-oblique').addEventListener('click', function () {
const uri = neonView.view.getCurrentPageURI();
neonView.getPageMEI(uri).then(meiString => {
// Load MEI document into parser
const parser = new DOMParser();
const meiDoc = parser.parseFromString(meiString, 'text/xml');
const mei = meiDoc.documentElement;
const ncs = Array.from(mei.getElementsByTagName('nc'));

let hasInvalidOblique = false;
const chainAction: EditorAction = {
action: 'chain',
param: []
};
const param = new Array<EditorAction>();
let ncIdx = 0;
while (ncIdx < ncs.length) {
if (ncs[ncIdx].getAttribute('ligated')) {
if ((ncIdx < ncs.length-1 && !ncs[ncIdx+1].getAttribute('ligated')) || (ncIdx == ncs.length-1)) {
// If nc is ligated, and the next nc is not
// Or, nc is ligated, but already at the end (there is no next)\
hasInvalidOblique = true;
param.push({
action: 'set',
param: {
elementId: ncs[ncIdx].getAttribute('xml:id'),
attrType: 'ligated',
attrValue: ''
}
});
}
ncIdx += 2;
}
ncIdx += 1;
}

if (!hasInvalidOblique) {
Notification.queueNotification('No invalid obliques found', 'warning');
}
else {
chainAction.param = param;
neonView.edit(chainAction, neonView.view.getCurrentPageURI()).then((result) => {
if (result) {
Notification.queueNotification('Untoggled invalid obliques', 'success');
} else {
Notification.queueNotification('Failed to untoggle invalid obliques', 'error');
}
neonView.updateForCurrentPage();
});
}
});
});

document.getElementById('untoggle-invalid-syls').addEventListener('click', function () {
const uri = neonView.view.getCurrentPageURI();
neonView.getPageMEI(uri).then(meiString => {
Expand Down

0 comments on commit 399fa98

Please sign in to comment.