Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
en:create:timer-display [12.01.2016 09:21] – [Implementation] Update adminen:create:timer-display [12.01.2016 09:37] – Added countdown script admin
Line 46: Line 46:
  
 <code html> <code html>
-<div id="myObjective">+<div id="myObject">
 <h1>Heading</h1> <h1>Heading</h1>
 <p>You can read the secret text here.</p> <p>You can read the secret text here.</p>
Line 56: Line 56:
  
 <code html> <code html>
-<div id="myQuestion">+<div id="myObject">
 </code> </code>
  
Line 65: Line 65:
 **Tip:** This is not necessary for questions because they already have an HTML ID ([[:en:create:dynamic|Immediately Show Questions when a Certain Option is Selected]]). **Tip:** This is not necessary for questions because they already have an HTML ID ([[:en:create:dynamic|Immediately Show Questions when a Certain Option is Selected]]).
  
 +The HTML/JavaScript code that takes care of hiding would look like this:
  
-===== Placeholder for the Missing Button =====+<code html> 
 +<script type="text/javascript"> 
 +<!-- 
 +  
 +// Funktion zum Einblenden der Knöpfe 
 +function showContent() { 
 +  var content = document.getElementById("myObject"); 
 +  // Den normalen Anzeigemodus wiederherstellen 
 +  content.style.display = ""; 
 +
 +  
 +// Nach dem Laden der Fragebogen-Seite das Script starten 
 +SoSciTools.attachEvent(window, "load", 
 +  function() { 
 +    // Objekt heraussuchen 
 +    var content = document.getElementById("myObject"); 
 +    // Ausblenden 
 +    content.style.display = "none"; 
 +    // Den Timer starten 
 +    window.setTimeout(showContent, 60000); // Nach 1 Min = 60.000 ms 
 +  } 
 +); 
 +  
 +// --> 
 +</script> 
 +</code> 
 + 
 + 
 +===== Placeholder for the Button =====
  
 With this solution, the layout is slightly altered when the button appears -- the page gets bigger. If you do not want this, you can hide the content with the CSS attribute ''visibility'', instead of with ''display'': With this solution, the layout is slightly altered when the button appears -- the page gets bigger. If you do not want this, you can hide the content with the CSS attribute ''visibility'', instead of with ''display'':
Line 92: Line 121:
   }   }
 ); );
 +
 +// -->
 +</script>
 +</code>
 +
 +
 +===== Display Countdown =====
 +
 +It may be irritation for respondents if the "next" button is missing. Therefore, it may be useful to display a countdown instead. Use the following HTML/JavaScript code to do so:
 +
 +<code javascript>
 +<script type="text/javascript">
 +<!--
 +
 +var countdown = 30;
 +var countdownDisplay;
 +var countdownTimer;
 +// "submit0" is the next button,
 +// use "buttonsAuto" instead to include the back button as well
 +var buttonID = "submit0";  
 +
 +function countdownStart() {
 +  // Next button
 +  var button = document.getElementById(buttonID);
 +  // Create countdown element
 +  countdownDisplay = document.createElement("div");
 +  var cd = countdownDisplay;
 +  cd.style.display = "inline-block";
 +  cd.style.textAlign = "center";
 +  cd.style.fontWeight = "bold";
 +  cd.style.width = button.offsetWidth + "px";
 +  cd.style.height = button.offsetHeight + "px";
 +  // Init countdown
 +  button.parentNode.appendChild(countdownDisplay);
 +  countdownRefresh();
 +  // Hide next button
 +  button.style.display = "none";
 +  // Start countdown
 +  countdownTimer = window.setInterval(countDown, 1000);
 +}
 +
 +function countDown() {
 +  if (countdown > 1) {
 +    countdown--;
 +    countdownRefresh();
 +  } else {
 +    window.clearTimeout(countdownTimer);
 +    // Display nextbutton
 +    var button = document.getElementById(buttonID);
 +    button.style.display = "";
 +    // Remove countdown
 +    button.parentNode.removeChild(countdownDisplay);
 +  }
 +}
 +
 +function countdownRefresh() {
 +  // Clear
 +  while (countdownDisplay.lastChild) {
 +    countdownDisplay.removeChild(countdownDisplay.lastChild);
 +  }
 +  // Display
 +  var content = document.createTextNode(countdown + " sec.");
 +  countdownDisplay.appendChild(content );
 +}
 +
 +SoSciTools.attachEvent(window, "load", countdownStart);
  
 // --> // -->
 </script> </script>
 </code> </code>
en/create/timer-display.txt · Last modified: 12.08.2022 19:26 by admin
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
Driven by DokuWiki