mirror of
https://github.com/finos/SymphonyElectron.git
synced 2025-01-05 21:54:05 -06:00
cc39f43ee7
- Implement a functionality to display snack bar - Localize snack bar - Move key press logic to windowMgr - Center snackbar - Add functionality to remove snackbar on leave-full-screen event - Add safety check - optimize code to listen keydown event only if the window is in full screen
54 lines
1.6 KiB
JavaScript
54 lines
1.6 KiB
JavaScript
const snackBarContent = require('./content').snackBarContent;
|
|
|
|
class SnackBar {
|
|
|
|
constructor() {
|
|
this.body = document.getElementsByTagName('body');
|
|
this.domParser = new DOMParser();
|
|
|
|
const snackBar = this.domParser.parseFromString(snackBarContent, 'text/html');
|
|
this.snackBar = snackBar.getElementById('snackbar');
|
|
}
|
|
|
|
/**
|
|
* Method that displays a snack bar for 3 sec
|
|
*/
|
|
showSnackBar(content) {
|
|
if (content && typeof content === 'object') {
|
|
const i18nNodes = this.snackBar.querySelectorAll('[data-i18n-text]');
|
|
|
|
for (let node of i18nNodes) {
|
|
if (node.attributes['data-i18n-text'] && node.attributes['data-i18n-text'].value) {
|
|
node.innerText = content[node.attributes['data-i18n-text'].value] || node.attributes['data-i18n-text'].value;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (this.body && this.body.length > 0 && this.snackBar) {
|
|
this.body[0].appendChild(this.snackBar);
|
|
this.snackBar.className = "show";
|
|
this.snackBarTimmer = setTimeout(() => {
|
|
this.body[0].removeChild(this.snackBar);
|
|
}, 3000);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Method that removes snack bar from the DOM
|
|
*/
|
|
removeSnackBar() {
|
|
if (this.body && this.body.length > 0 && this.snackBar) {
|
|
if (document.getElementById('snackbar')) {
|
|
this.body[0].removeChild(this.snackBar);
|
|
if (this.snackBarTimmer) {
|
|
clearTimeout(this.snackBarTimmer);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = {
|
|
SnackBar,
|
|
}; |