Difference between revisions of "MediaWiki:Common.js"

From MakeICT Wiki
Jump to navigationJump to search
Line 11: Line 11:
 
   var getTaskProperty = function(task, property){
 
   var getTaskProperty = function(task, property){
 
     console.log(".makeict-todo-" + property);
 
     console.log(".makeict-todo-" + property);
     return $(task).find(".makeict-todo-" + property)[0].innerText;
+
     return $(task).find(".makeict-todo-" + property)[0].innerText.toLowerCase();
 
   }
 
   }
  
Line 25: Line 25:
 
   };
 
   };
  
 +
  cloneNodesToList($("#makeict-decision-summary")[0], $(".makeict-decision"));
  
   cloneNodesToList($("#makeict-decision-summary")[0], $(".makeict-decision"));
+
   var tasks = $(".makeict-todo");
   cloneNodesToList($("#makeict-todo-summary")[0], $(".makeict-todo").sort(taskCompare));
+
  try{
 +
    tasks.sort(taskCompare);
 +
  }catch(exc){}
 +
 
 +
   cloneNodesToList($("#makeict-todo-summary")[0], tasks);
 
}());
 
}());

Revision as of 12:09, 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.toLowerCase();
  }

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

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

  var tasks = $(".makeict-todo");
  try{
    tasks.sort(taskCompare);
  }catch(exc){}

  cloneNodesToList($("#makeict-todo-summary")[0], tasks);
}());