Difference between revisions of "MediaWiki:Common.js"
From MakeICT Wiki
Jump to navigationJump to searchLine 7: | Line 7: | ||
list.appendChild(listItem); | list.appendChild(listItem); | ||
} | } | ||
+ | }; | ||
+ | |||
+ | var getTaskProperty = function(task, 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-decision-summary")[0], $(".makeict-decision")); | ||
+ | cloneNodesToList($("#makeict-todo-summary")[0], $(".makeict-todo").sort(taskCompare)); | ||
}()); | }()); |
Revision as of 12:06, 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){
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));
}());