-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Now we centralize the initialization of most elements through an init function that can be called when first loading a page and also when loading modals
- Loading branch information
Showing
44 changed files
with
333 additions
and
548 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
freesound/static/bw-frontend/src/components/afterDownloadModal.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
import {handleGenericModal} from './modal'; | ||
|
||
|
||
const bindDownloadSoundButtons = () => { | ||
const prepareAfterDownloadSoundModals = () => { | ||
const downloadButtonElements = document.getElementsByClassName('sound-download-button'); | ||
downloadButtonElements.forEach(element => { | ||
const showModalUrl = element.dataset.showAfterDownloadModalUrl; | ||
element.addEventListener('click', () => { | ||
handleGenericModal(showModalUrl, () => {}, () => {}, false, true); | ||
handleGenericModal(showModalUrl, undefined, undefined, false, true); | ||
}); | ||
}); | ||
} | ||
|
||
bindDownloadSoundButtons(); | ||
export { prepareAfterDownloadSoundModals }; |
63 changes: 27 additions & 36 deletions
63
freesound/static/bw-frontend/src/components/asyncSection.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,30 @@ | ||
import {showToast} from "./toast"; | ||
import {initPlayersInModal} from './modal'; | ||
import {bindSimilarSoundModals} from './similarSoundsModal'; | ||
import {bindBookmarkSoundButtons} from './bookmarkSound'; | ||
import {bindRemixGroupModals} from './remixGroupModal'; | ||
import { showToast } from "./toast"; | ||
import { initializeStuffInContainer } from "../utils/initHelper"; | ||
|
||
const asyncSectionPlaceholders = document.getElementsByClassName('async-section'); | ||
|
||
const initPlayersAndPlayerModalsInElement = (element) => { | ||
initPlayersInModal(element); | ||
bindSimilarSoundModals(); | ||
bindBookmarkSoundButtons(); | ||
bindRemixGroupModals(); | ||
} | ||
|
||
asyncSectionPlaceholders.forEach(element => { | ||
const contentUrl = element.dataset.asyncSectionContentUrl; | ||
|
||
const req = new XMLHttpRequest(); | ||
req.open('GET', contentUrl); | ||
req.onload = () => { | ||
if (req.status >= 200 && req.status < 300) { | ||
element.innerHTML = req.responseText; | ||
|
||
// Make sure we initialize sound/pack players inside the async section | ||
initPlayersAndPlayerModalsInElement(element); | ||
} else { | ||
const prepareAsyncSections = (container) => { | ||
const asyncSectionPlaceholders = container.getElementsByClassName('async-section'); | ||
asyncSectionPlaceholders.forEach(element => { | ||
const contentUrl = element.dataset.asyncSectionContentUrl; | ||
const req = new XMLHttpRequest(); | ||
req.open('GET', contentUrl); | ||
req.onload = () => { | ||
if (req.status >= 200 && req.status < 300) { | ||
element.innerHTML = req.responseText; | ||
// Make sure we initialize sound/pack players inside the async section | ||
initializeStuffInContainer(element, true, false); | ||
} else { | ||
// Unexpected errors happened while processing request: show toast | ||
showToast('Unexpected errors occurred while loading some of the content of this page. Please try again later...') | ||
} | ||
}; | ||
req.onerror = () => { | ||
// Unexpected errors happened while processing request: show toast | ||
showToast('Unexpected errors occurred while loading some of the content of this page. Please try again later...') | ||
} | ||
}; | ||
req.onerror = () => { | ||
// Unexpected errors happened while processing request: show toast | ||
showToast('Unexpected errors occurred while loading some of the content of this page. Please try again later...') | ||
}; | ||
|
||
// Send the form | ||
req.send(); | ||
}); | ||
}; | ||
|
||
// Send the form | ||
req.send(); | ||
}); | ||
} | ||
|
||
export {prepareAsyncSections}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 7 additions & 12 deletions
19
freesound/static/bw-frontend/src/components/commentsModal.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,19 @@ | ||
import {handleGenericModal, bindModalActivationElements, activateModalsIfParameters, initPlayersInModal, stopPlayersInModal, bindConfirmationModalElements} from './modal'; | ||
import {bindFlagUserElements} from './flagging'; | ||
import {handleGenericModal, bindModalActivationElements, activateModalsIfParameters} from './modal'; | ||
|
||
|
||
const handleCommentsModal = (modalUrl, modalActivationParam, atPage) => { | ||
if ((atPage !== undefined) && modalUrl.indexOf('&page') == -1){ | ||
modalUrl += '&page=' + atPage; | ||
} | ||
handleGenericModal(modalUrl, (modalContainer) => { | ||
initPlayersInModal(modalContainer); | ||
bindConfirmationModalElements(modalContainer); // For the "delete comment" buttons which need confirmation | ||
bindFlagUserElements(modalContainer); // For the "flag comment" buttons | ||
}, (modalContainer) => { | ||
stopPlayersInModal(modalContainer); | ||
}, true, true, modalActivationParam); | ||
handleGenericModal(modalUrl, undefined, undefined, true, true, modalActivationParam); | ||
} | ||
|
||
const bindCommentsModals = (container) => { | ||
bindModalActivationElements('[data-toggle="comments-modal"]', handleCommentsModal, container); | ||
} | ||
|
||
bindCommentsModals(); | ||
activateModalsIfParameters('[data-toggle="comments-modal"]', handleCommentsModal); | ||
const activateCommentsModalsIfParameters = () => { | ||
activateModalsIfParameters('[data-toggle="comments-modal"]', handleCommentsModal); | ||
} | ||
|
||
export {bindCommentsModals}; | ||
export {bindCommentsModals, activateCommentsModalsIfParameters}; |
20 changes: 7 additions & 13 deletions
20
freesound/static/bw-frontend/src/components/downloadersModals.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,19 @@ | ||
import {handleGenericModal, bindModalActivationElements, activateModalsIfParameters, initPlayersInModal, stopPlayersInModal} from './modal'; | ||
import {handleGenericModal, bindModalActivationElements, activateModalsIfParameters} from './modal'; | ||
|
||
const handleDownloadersModal = (modalUrl, modalActivationParam, atPage) => { | ||
if ((atPage !== undefined) && modalUrl.indexOf('&page') == -1){ | ||
modalUrl += '&page=' + atPage; | ||
} | ||
handleGenericModal(modalUrl, (modalContainer) => { | ||
// This method is used both for the "users that downloaded sound/pack" and the "sounds/packs downloaded by user" modals | ||
// The second type displays sounds players in the modal so we need to initialize them when modal is loaded | ||
initPlayersInModal(modalContainer); | ||
}, (modalContainer) => { | ||
// This method is used both for the "users that downloaded sound/pack" and the "sounds/packs downloaded by user" modals | ||
// The second type displays sounds players in the modal so we need to stop them when modal is closed | ||
stopPlayersInModal(modalContainer); | ||
}, true, true, modalActivationParam); | ||
handleGenericModal(modalUrl, undefined, undefined, true, true, modalActivationParam); | ||
} | ||
|
||
const bindDownloadersModals = (container) => { | ||
bindModalActivationElements('[data-toggle="downloaders-modal"]', handleDownloadersModal, container); | ||
} | ||
|
||
bindDownloadersModals(); | ||
activateModalsIfParameters('[data-toggle="downloaders-modal"]', handleDownloadersModal); | ||
const activateDownloadersModalsIfParameters = () => { | ||
activateModalsIfParameters('[data-toggle="downloaders-modal"]', handleDownloadersModal); | ||
} | ||
|
||
|
||
export {bindDownloadersModals}; | ||
export {bindDownloadersModals, activateDownloadersModalsIfParameters}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.