Template:DoneCounter

From 2009.igem.org

(Difference between revisions)
(Moved doneCounter to template.)
(Try onLoad)
Line 1: Line 1:
-
<!-- This counts the number of todo/done items and puts the results in the element with class doneCount. -->
+
<includeonly><html>
-
<html>
+
<script type="text/javascript" src="http://o.aolcdn.com/dojo/1.3.0/dojo/dojo.xd.js"></script>
<script type="text/javascript" src="http://o.aolcdn.com/dojo/1.3.0/dojo/dojo.xd.js"></script>
<script type="text/javascript">
<script type="text/javascript">
-
var doneCounts = dojo.query('.doneCount');
+
dojo.addOnLoad(function(){
-
for(var i=0; i<doneCounts.length; i++) {
+
  var doneCounts = dojo.query('.doneCount');
-
  var doneCount = doneCounts[i];
+
  for(var i=0; i<doneCounts.length; i++) {
-
  var parentElement = doneCount.parentNode;
+
    var doneCount = doneCounts[i];
-
  while(!(!parentElement || parentElement.nodeName=='UL' || parentElement.nodeName=='OL' || parentElement.nodeName=='TABLE')) parentElement = parentElement.nextSibling;
+
    var parentElement = doneCount.parentNode;
-
  var numTodo = dojo.query('.todo',parentElement).length;
+
    while(!(!parentElement ||
-
  var numDone = dojo.query('.done',parentElement).length;
+
            parentElement.nodeName=='UL' ||
-
  doneCount.innerHTML = ' (' + numDone + ' out of ' + (numDone+numTodo) + ' done)';
+
            parentElement.nodeName=='OL' ||
-
}
+
            parentElement.nodeName=='TABLE')) {
 +
      parentElement = parentElement.nextSibling;
 +
    }
 +
    var numTodo = dojo.query('.todo',parentElement).length;
 +
    var numDone = dojo.query('.done',parentElement).length;
 +
    doneCount.innerHTML = ' (' + numDone + ' out of ' + (numDone+numTodo) + ' done)';
 +
});
</script>
</script>
-
</html>
+
</html></includeonly><noinclude>This is a script that counts the number of done tasks in a list and puts a string like " (8 out of 9 done)" in fields (spans) with class="doneCount".</noinclude>

Revision as of 13:53, 14 May 2009

This is a script that counts the number of done tasks in a list and puts a string like " (8 out of 9 done)" in fields (spans) with class="doneCount".