Template:DoneCounter

From 2009.igem.org

(Difference between revisions)
m (Bug fixed)
m (Trying Dojo 1.3.2)
 
(2 intermediate revisions not shown)
Line 1: Line 1:
-
<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.2/dojo/dojo.xd.js"></script>
-
<script type="text/javascript">
+
<script type="text/javascript" src="/Template:DoneCounter/Counter.js?action=raw"></script>
-
/*<![CDATA[*/
+
</html><noinclude>This is a script that counts the number of done items in a task list and puts it in the element with class doneCount above the list. Like this<span class="doneCount"></span>:
-
dojo.addOnLoad(function(){
+
 
-
  var doneCounts = dojo.query('.doneCount');
+
* {{todo}} I definitely have to do this.
-
  for(var i=0; i<doneCounts.length; i++) {
+
* {{todo|And this.}}
-
    var doneCount = doneCounts[i];
+
* {{done}} But I did this.
-
    var parentElement = doneCount.parentNode;
+
</noinclude>
-
    while(!(!parentElement ||
+
-
            parentElement.nodeName=='UL' ||
+
-
            parentElement.nodeName=='OL' ||
+
-
            parentElement.nodeName=='TABLE')) { // This works around ampersands not working.
+
-
      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>
+
-
</html></includeonly><noinclude>This is a script that counts the number of done items in a task list and puts it in the element with class doneCount above the list.</noinclude>
+

Latest revision as of 12:40, 30 July 2009

This is a script that counts the number of done items in a task list and puts it in the element with class doneCount above the list. Like this:

  • TODO I definitely have to do this.
  • And this.
  • DONE But I did this.