Difference between revisions of "MediaWiki:Common.js"
From MakeICT Wiki
Jump to navigationJump to searchLine 15: | Line 15: | ||
var taskCompare = function(taskA, taskB){ | var taskCompare = function(taskA, taskB){ | ||
− | + | var props = ["who", "when"]; | |
− | var a = getTaskProperty(taskA, | + | for(i in props){ |
− | var b = getTaskProperty(taskB, | + | var a = getTaskProperty(taskA, props[i]); |
+ | var b = getTaskProperty(taskB, props[i]); | ||
if(a > b) return 1; | if(a > b) return 1; | ||
if(b > a) return -1; | if(b > a) return -1; |
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){
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"));
cloneNodesToList($("#makeict-todo-summary")[0], $(".makeict-todo").sort(taskCompare));
}());