Skip to content

Commit

Permalink
clean code and adjust values
Browse files Browse the repository at this point in the history
  • Loading branch information
TRMSC committed Nov 16, 2023
1 parent 247294f commit 2126c91
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions docs/src/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ generateScene = () => {
// Show result
let show = document.getElementById('resultpart');
show.style.display = "";
scrollTarget('resultpart');
scrollTarget('resultpart', 150);

// Get template
let templateName = document.getElementById('imagescene-template').value;
Expand Down Expand Up @@ -553,36 +553,51 @@ generateScene = () => {
*/
handleResultPreview = () => {

// Create test image
let testImage = new Image();
testImage.src = url;

// Check image
return new Promise((resolve) => {

testImage.onload = function() {
resolve(true);
};

testImage.onerror = function() {
resolve(false);
};

}).then((isValid) => {

if (isValid) {

// Image source is given
document.getElementById('imagescene-result-preview').innerHTML = templateContent;

} else {

// Image source isn't available
document.getElementById('imagescene-result-preview').textContent =
"Für diese Bildszene kann keine Vorschau angezeigt werden. " +
"Möglicherweise liegt das daran, dass die Bildquelle in einem passwortgeschützten Raum liegt " +
"(z.B. in Moodle) und im Browser dort aktuell keine Anmeldung besteht.";

}

// Function for toggling visibility
function toggleVisibility(elementId) {
let element = document.getElementById(elementId);
element.classList.toggle('ic-d-none');
}

// Function calls for toggling
toggleVisibility('result-preview-container');
toggleVisibility('ic-preview-show');
toggleVisibility('ic-preview-hide');
toggleVisibility('ic-preview-hide');

// Scroll to preview
scrollTarget('resultpart', 50);

});

Expand All @@ -593,17 +608,18 @@ handleResultPreview = () => {
* Scroll to target
*
* @function scrollTarget
* @param id The target ID
* @param {string} id The target ID
* @param {number} value The scrolling distance
* @returns {void}
*
*/
scrollTarget = (id) => {
scrollTarget = (id, value) => {

// Get target
const target = document.getElementById(id);

// Calculate position
const targetPosition = target.getBoundingClientRect().top + window.scrollY - 50;
const targetPosition = target.getBoundingClientRect().top + window.scrollY - value;

// Scroll to position
window.scrollTo({
Expand Down

0 comments on commit 2126c91

Please sign in to comment.