fix voting/flagging from a7299e84

If the Lobster replacement class isn't in the global scope, the existing
Lobsters can't refer to it. But if it's in the global scope, the DOM isn't yet
loaded for it to read the current username. When the old class is entirely
replaced, insantiation of the class can move back into onPageLoad().
This commit is contained in:
Peter Bhat Harkins 2022-06-29 09:18:11 -05:00
parent 4c3c17710b
commit 48b23c148e
1 changed files with 5 additions and 4 deletions

View File

@ -316,8 +316,8 @@ const removeExtraInputs = () => {
}
class _LobstersFunction {
constructor () {
this.curUser = document.body.getAttribute('data-username');
constructor (username) {
this.curUser = null;
this.storyFlagReasons = ({
<%= Vote::STORY_REASONS.map{|k,v| "'#{k}': '#{v}'" }.join(", ") %>
@ -544,12 +544,13 @@ class _LobstersFunction {
}
}
const Lobster = new _LobstersFunction();
onPageLoad(() => {
Lobster.curUser = document.body.getAttribute('data-username'); // hack
// Global Functions
const Lobster = new _LobstersFunction();
on('click', '.markdown_help_label', (event) => {
parentSelector(event.target, '.markdown_help_toggler').querySelector('.markdown_help').classList.toggle('display-block');
});