Sindbad~EG File Manager

Current Path : /home/beeson/public_html/WebMathXpert/
Upload File :
Current File : //home/beeson/public_html/WebMathXpert/commentaryModal.js

// you need to have access to wrapSVGtext.js to use this file. 
// CSS for the modal
const style = document.createElement('style');
style.innerHTML = `
/* Modal styles */

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    background-color: #f1f1f1;
    border-bottom: 1px solid #ccc;
    width: 80%; /* Same width as .modal-content */
    max-width: 400px; /* Same max-width as .modal-content */
    margin: 0 auto; /* Center the header */
    box-sizing: border-box; /* Ensure padding and border are included in the width */
}

.modal-title {
    font-size: 14px;
    font-weight: bold;
}

.modal {
    display: none;
    position: fixed;
    z-index: 1;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.4);
}

.modal-content {
    background-color: #fefefe;
    margin: auto;
    border: 1px solid #888;
    width: 80%;
    max-width: 400px;
    position: relative;
	 padding: 0px;
	 display:block;
}

.close-button {
    color: #aaa;
    float: right;
    font-size: 14px;
    font-weight: normal;
    cursor: pointer;
}

.close-button:hover,
.close-button:focus {
    color: black;
    text-decoration: none;
    cursor: pointer;
}

#commentaryContent {
    display: block; /* Ensure it expands to fit the content */
    font-family: 'Times New Roman', Times, serif;
    font-size: 14px;
    word-wrap: break-word;
    word-break: break-all;
    white-space: pre-wrap; /* Use pre-wrap for SVG text elements */
    line-height: 1.5;
    overflow: hidden;  /* to prevent accidentally disabling the close button */
	 min-height: 260px;
	 position:relative
	 padding:20px
}

#commentaryContent svg {
    width: 100%; 
    height: 100%; 
    display: block; /* Make sure SVG is treated as a block element */
}

`;
document.head.appendChild(style);

// HTML for the modal
const modalHtml = `
<div id="commentaryModal" class="modal">
    <div class="modal-header">
        <span class="modal-title">Author's Commentary</span>
        <span class="close-button">Close</span>
    </div>
    <div class="modal-content">   
       <div id="commentaryContent"></div>	   
    </div>
</div>


`;
document.body.insertAdjacentHTML('beforeend', modalHtml);


// JavaScript to get and display the commentary
function displayAuthorCommentary(maxwidth) {
	let commentary = document.getElementById('remarks');
    if (commentary) {
        display_commentary(commentary,maxwidth);
    }
}

function display_commentary(commentary,maxwidth) {
    // Clone the commentary SVG element to prevent any modifications to the original
    let commentaryClone = commentary.cloneNode(true);
    commentaryClone.style.display = "block";  // Make it visible 
	 
	 wrapSVGTextWithTspans(commentaryClone,maxwidth );
	 // console.log("Updated SVG:", commentaryClone.outerHTML); 
  
    // Insert the cloned commentary into the modal content
    let commentaryContent = document.getElementById('commentaryContent');
    commentaryContent.innerHTML = ''; // Clear any existing content
    commentaryContent.appendChild(commentaryClone);
	 // Get the height of commentaryClone
	 // The following code doesn't work.  So I gave up and set the minimum height hard-coded in the CSS above
	 // const commentaryCloneBBox = commentaryClone.getBBox();
	 // const commentaryCloneHeight = commentaryCloneBBox.height;
	 // Set the min-height of commentaryContent to 20 pixels more than commentaryClone's height
	 //commentaryContent.style.minHeight = (commentaryCloneHeight + 20) + 'px';

    // Display the modal
    let modal = document.getElementById('commentaryModal');
    modal.style.display = 'block';

    // Close button handler
    let closeButton = document.querySelector('.close-button');
    closeButton.onclick = function() {
        modal.style.display = 'none';
		  console.log("close clicked");
    };

    // Close the modal when clicking outside the modal content
    window.onclick = function(event) {
        if (event.target === modal) {
            modal.style.display = 'none';
        }
    };
}

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists