Difference between revisions of "MediaWiki:Common.js"

From MakeICT Wiki
Jump to navigationJump to search
Line 10: Line 10:
  
 
   var getTaskProperty = function(task, property){
 
   var getTaskProperty = function(task, property){
 +
    console.log(".makeict-todo-" + property);
 
     return $(task).find(".makeict-todo-" + property)[0].innerText;
 
     return $(task).find(".makeict-todo-" + property)[0].innerText;
 
   }
 
   }

Revision as of 12:07, 8 March 2015

/* Any JavaScript here will be loaded for all users on every page load. */
(function () {
  var cloneNodesToList = function(list, nodes) {
    for(var i=0; i<nodes.length; i++){
      var listItem = document.createElement("li");
      listItem.appendChild(nodes[i].cloneNode(true));
      list.appendChild(listItem);
    }
  };

  var getTaskProperty = function(task, property){
    console.log(".makeict-todo-" + property);
    return $(task).find(".makeict-todo-" + property)[0].innerText;
  }

  var taskCompare = function(taskA, taskB){
    for(p in ["who", "when"]){
      var a = getTaskProperty(taskA, p);
      var b = getTaskProperty(taskB, p);
      if(a > b) return 1;
      if(b > a) return -1;
    }
    return 0;
  };


  cloneNodesToList($("#makeict-decision-summary")[0], $(".makeict-decision"));
  cloneNodesToList($("#makeict-todo-summary")[0], $(".makeict-todo").sort(taskCompare));
}());