diff --git a/Journal.js b/Journal.js index 7dc3c32a1..e74122b5f 100644 --- a/Journal.js +++ b/Journal.js @@ -1020,101 +1020,96 @@ class JournalManager{ display_note(id, statBlock = false){ let self=this; - $(`div.note[data-id='${id}']`)?.dialog("close"); - let note=$(`
`); + let noteAlreadyOpen = $(`div.note[data-id='${id}']`).length>0; - note.attr('title',self.notes[id].title); - if(window.DM){ - let visibility_container=$("
"); - + let note= noteAlreadyOpen ? $(`div.note[data-id='${id}']`) : $(`
`); + if(!noteAlreadyOpen){ + note.attr('title',self.notes[id].title); + if(window.DM){ + let visibility_container=$("
"); - let toggle_container = $(`
"); - let visibility_row = $(`
`) - visibility_row.append(visibility_toggle) - toggle_container.append(visibility_row); - visibility_toggle.change(function(){ - - window.JOURNAL.note_visibility(id,visibility_toggle.is(":checked")); - window.JOURNAL.build_journal(); - toggle_container.find(`input:not([name='allPlayers'])`).prop('disabled', visibility_toggle.is(":checked")); - toggle_container.find(`input:not([name='allPlayers'])`).prop('checked', visibility_toggle.is(":checked")); - - }); + let toggle_container = $(`
`); - let visibility_row = $(`
`) - - visibility_row.append(visibility_toggle) + let visibility_toggle=$(""); + let visibility_row = $(`
`) + visibility_row.append(visibility_toggle) + toggle_container.append(visibility_row); + visibility_toggle.change(function(){ - visibility_toggle.prop("checked",(self.notes[id]?.player instanceof Array && self.notes[id]?.player.includes(`${window.playerUsers[i].userId}`))); + window.JOURNAL.note_visibility(id,visibility_toggle.is(":checked")); + window.JOURNAL.build_journal(); + toggle_container.find(`input:not([name='allPlayers'])`).prop('disabled', visibility_toggle.is(":checked")); + toggle_container.find(`input:not([name='allPlayers'])`).prop('checked', visibility_toggle.is(":checked")); - visibility_toggle.change(function(){ - let sharedUsers = toggle_container.find(`input:checked:not([name='allPlayers'])`).toArray().map(d => d.name); - if(sharedUsers.length == 0) - sharedUsers = false; - window.JOURNAL.note_visibility(id,sharedUsers); - window.JOURNAL.build_journal(); - }); - - toggle_container.append(visibility_row); - } - } - - visibility_toggle.prop("checked",self.notes[id].player == true); - if(visibility_toggle.is(":checked")) - toggle_container.find(`input:not([name='allPlayers'])`).prop('disabled', true); - else - toggle_container.find(`input:not([name='allPlayers'])`).prop('disabled', false); - - - let shareWithPlayer = $(""); - shareWithPlayer.append(toggle_container); - visibility_container.append(shareWithPlayer); - - let popup_btn=$(""); - - popup_btn.click(function(){ - window.MB.sendMessage('custom/myVTT/note',{ - id: id, - note:self.notes[id], - popup: true, - }); - }); - - visibility_container.append(popup_btn); + }); - let force_close_popup_btn=$("") - force_close_popup_btn.click(function(){ - window.MB.sendMessage('custom/myVTT/note',{ - id: id, - note:self.notes[id], - popup: false, - }); - }); - - visibility_container.append(force_close_popup_btn); - - let edit_btn=$(""); - edit_btn.click(function(){ - note.remove(); - window.JOURNAL.edit_note(id, statBlock); - }); - - visibility_container.append(edit_btn); - - note.append(visibility_container); - + for(let i in window.playerUsers){ + if(toggle_container.find(`input[name='${window.playerUsers[i].userId}']`).length == 0){ + let visibility_toggle=$(``); + let visibility_row = $(`
`) + + visibility_row.append(visibility_toggle) + + visibility_toggle.prop("checked",(self.notes[id]?.player instanceof Array && self.notes[id]?.player.includes(`${window.playerUsers[i].userId}`))); + + visibility_toggle.change(function(){ + let sharedUsers = toggle_container.find(`input:checked:not([name='allPlayers'])`).toArray().map(d => d.name); + if(sharedUsers.length == 0) + sharedUsers = false; + window.JOURNAL.note_visibility(id,sharedUsers); + window.JOURNAL.build_journal(); + }); + + toggle_container.append(visibility_row); + } + } + + visibility_toggle.prop("checked",self.notes[id].player == true); + + if(visibility_toggle.is(":checked")) + toggle_container.find(`input:not([name='allPlayers'])`).prop('disabled', true); + else + toggle_container.find(`input:not([name='allPlayers'])`).prop('disabled', false); + + + let shareWithPlayer = $(""); + shareWithPlayer.append(toggle_container); + visibility_container.append(shareWithPlayer); + + let popup_btn=$(""); + + popup_btn.click(function(){ + window.MB.sendMessage('custom/myVTT/note',{ + id: id, + note:self.notes[id], + popup: true, + }); + }); + + visibility_container.append(popup_btn); + + let edit_btn=$(""); + edit_btn.click(function(){ + note.remove(); + window.JOURNAL.edit_note(id, statBlock); + }); + + visibility_container.append(edit_btn); + + note.append(visibility_container); + + } + } + + let note_text= noteAlreadyOpen ? note.find('.note-text') : $("
"); + if(noteAlreadyOpen){ + note_text.empty(); } - let note_text=$("
"); note_text.append(self.notes[id].text); // valid tags are controlled by tinyMCE.init() this.translateHtmlAndBlocks(note_text); @@ -1146,68 +1141,72 @@ class JournalManager{ $(this).find('p').remove(); $(this).after(input) }) - note.append(note_text); + if(!noteAlreadyOpen){ + note.append(note_text); + } note.find("a").attr("target","_blank"); - note.dialog({ - draggable: true, - width: 860, - height: 600, - position:{ - my: "center", - at: "center-200", - of: window - }, - close: function( event, ui ) { - $(this).remove(); + if(!noteAlreadyOpen){ + note.dialog({ + draggable: true, + width: 860, + height: 600, + position:{ + my: "center", + at: "center-200", + of: window + }, + close: function( event, ui ) { + $(this).remove(); + } + }); + $("[role='dialog']").draggable({ + containment: "#windowContainment", + start: function () { + $("#resizeDragMon").append($('
')); + $("#sheet").append($('
')); + }, + stop: function () { + $('.iframeResizeCover').remove(); } - }); - $("[role='dialog']").draggable({ - containment: "#windowContainment", - start: function () { - $("#resizeDragMon").append($('
')); - $("#sheet").append($('
')); - }, - stop: function () { - $('.iframeResizeCover').remove(); - } - }); - $("[role='dialog']").resizable({ - start: function () { - $("#resizeDragMon").append($('
')); - $("#sheet").append($('
')); - }, - stop: function () { - $('.iframeResizeCover').remove(); - } - }); - - note.parent().mousedown(function() { - frame_z_index_when_click($(this)); - }); - let btn_popout=$(`
"`); - note.parent().append(btn_popout); - btn_popout.click(function(){ - let uiId = $(this).siblings(".note").attr("id"); - let journal_text = $(`#${uiId}.note .note-text`) - let title = self.notes[id]?.title?.trim() || $("#resizeDragMon .avtt-stat-block-container .mon-stat-block__name-link").text(); - popoutWindow(title, note, journal_text.width(), journal_text.height()); - removeFromPopoutWindow(title, ".visibility-container"); - removeFromPopoutWindow(title, ".ui-resizable-handle"); - $(window.childWindows[title].document).find("head").append(`