Skip to content

Commit

Permalink
Wrap updateDisplayAllBtn()
Browse files Browse the repository at this point in the history
  • Loading branch information
yinanazhou committed Jul 11, 2023
1 parent e5f1848 commit 492b85c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 57 deletions.
25 changes: 25 additions & 0 deletions src/DisplayPanel/DisplayControls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,31 @@ function setDisplayAllListener(): void {
});
}

/**
* Update `Display All` button status
*/
export function updateDisplayAllBtn(): void {
const displayAllBtn = document.getElementById('display-all-btn');
const displayInfo = document.getElementById('displayInfo') as HTMLInputElement;
const displayBBoxes = document.getElementById('displayBBox') as HTMLInputElement;
const displayText = document.getElementById('displayText') as HTMLInputElement;
const displayErrLog = document.getElementById('display-errors') as HTMLInputElement;

// if all options are selected,
// set "Display/Hide All" button to "Hide All".
if (displayInfo?.checked && displayBBoxes?.checked &&
displayText?.checked && displayErrLog?.checked) {
displayAllBtn.classList.add('selected');
displayAllBtn.innerHTML = 'Hide All';
} else {
// if "Display/Hide All" button is in "Hide All" mode, set it to "Display All" mode
if (displayAllBtn.classList.contains('selected')) {
displayAllBtn.classList.remove('selected');
displayAllBtn.innerHTML = 'Display All';
}
}
}

/**
* Load highlight settings from localStorage
*/
Expand Down
22 changes: 3 additions & 19 deletions src/InfoModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import NeonView from './NeonView';
import { InfoInterface } from './Interfaces';
import { Attributes, ClefAttributes } from './Types';
import { getSettings, setSettings } from './utils/LocalSettings';
import { updateDisplayAllBtn } from './DisplayPanel/DisplayControls';

/**
* Map of contours to neume names.
Expand All @@ -29,36 +30,19 @@ function startInfoVisibility (): void {
*/
function updateInfoVisibility (): void {
const neumeInfo = document.getElementById('neume_info');

const displayAllBtn = document.getElementById('display-all-btn');
const displayInfo = document.getElementById('displayInfo') as HTMLInputElement;
const displayBBoxes = document.getElementById('displayBBox') as HTMLInputElement;
const displayText = document.getElementById('displayText') as HTMLInputElement;
const displayErrLog = document.getElementById('display-errors') as HTMLInputElement;


// save setting to localStorage
setSettings({ displayInfo: displayInfo.checked });

if (displayInfo.checked) {
neumeInfo.setAttribute('style', '');
// scroll neume info into view
//neumeInfo.scrollIntoView({ behavior: 'smooth' });

// if this is the 3rd option to be checked (all three are selected),
// set "Display/Hide All" button to "Hide All".
if (displayInfo?.checked && displayBBoxes?.checked &&
displayText?.checked && displayErrLog?.checked) {
displayAllBtn.classList.add('selected');
displayAllBtn.innerHTML = 'Hide All';
}
} else {
neumeInfo.setAttribute('style', 'display: none');
// if "Display/Hide All" button is in "Hide All" mode, set it to "Display All" mode
if (displayAllBtn.classList.contains('selected')) {
displayAllBtn.classList.remove('selected');
displayAllBtn.innerHTML = 'Display All';
}
}
updateDisplayAllBtn();
}

/**
Expand Down
45 changes: 7 additions & 38 deletions src/TextView.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as Notification from './utils/Notification';
import NeonView from './NeonView';
import { unselect } from './utils/SelectTools';
import { updateHighlight } from './DisplayPanel/DisplayControls';
import { updateDisplayAllBtn, updateHighlight } from './DisplayPanel/DisplayControls';
import { TextViewInterface } from './Interfaces';
import { getSettings, setSettings } from './utils/LocalSettings';

Expand Down Expand Up @@ -76,12 +76,8 @@ class TextView implements TextViewInterface {
*/
updateBBoxVisibility (): void {

const displayAllBtn = document.getElementById('display-all-btn');
const displayInfo = document.getElementById('displayInfo') as HTMLInputElement;
const displayBBoxes = document.getElementById('displayBBox') as HTMLInputElement;
const displayText = document.getElementById('displayText') as HTMLInputElement;
const displayErrLog = document.getElementById('display-errors') as HTMLInputElement;


// save to localStorage
setSettings({ displayBBox: displayBBoxes.checked });

Expand All @@ -96,14 +92,6 @@ class TextView implements TextViewInterface {
if (this.neonView.getUserMode() !== 'viewer' && this.neonView.TextEdit !== undefined) {
this.neonView.TextEdit.initSelectByBBoxButton();
}

// if this is the 3rd option to be checked (all three are selected),
// set "Display/Hide All" button to "Hide All".
if (displayInfo?.checked && displayBBoxes?.checked &&
displayText?.checked && displayErrLog?.checked) {
displayAllBtn.classList.add('selected');
displayAllBtn.innerHTML = 'Hide All';
}
}
else {
if (document.getElementById('selByBBox')?.classList.contains('is-active')) {
Expand All @@ -125,13 +113,9 @@ class TextView implements TextViewInterface {
document.getElementById('selByBBox').style.display = 'none';
}
catch (e) {}

// if "Display/Hide All" button is in "Hide All" mode, set it to "Display All" mode
if (displayAllBtn.classList.contains('selected')) {
displayAllBtn.classList.remove('selected');
displayAllBtn.innerHTML = 'Display All';
}
}

updateDisplayAllBtn();
updateHighlight();
}

Expand All @@ -141,12 +125,8 @@ class TextView implements TextViewInterface {
*/
updateTextViewVisibility (): void {

const displayAllBtn = document.getElementById('display-all-btn');
const displayInfo = document.getElementById('displayInfo') as HTMLInputElement;
const displayBBoxes = document.getElementById('displayBBox') as HTMLInputElement;
const displayText = document.getElementById('displayText') as HTMLInputElement;
const displayErrLog = document.getElementById('display-errors') as HTMLInputElement;


// save to localStorage
setSettings({ displayText: displayText.checked });

Expand Down Expand Up @@ -209,23 +189,12 @@ class TextView implements TextViewInterface {

// scroll the syllable text bubble into view
//sylText.scrollIntoView({ behavior: 'smooth' });

// if this is the 3rd option to be checked (all three are selected),
// set "Display/Hide All" button to "Hide All".
if (displayInfo?.checked && displayBBoxes?.checked &&
displayText?.checked && displayErrLog?.checked) {
displayAllBtn.classList.add('selected');
displayAllBtn.innerHTML = 'Hide All';
}
}
else {
document.getElementById('syl_text').style.display = 'none';
// if "Display/Hide All" button is in "Hide All" mode, set it to "Display All" mode
if (displayAllBtn.classList.contains('selected')) {
displayAllBtn.classList.remove('selected');
displayAllBtn.innerHTML = 'Display All';
}
}

updateDisplayAllBtn();
}

/**
Expand Down

0 comments on commit 492b85c

Please sign in to comment.