Difference between revisions of "MediaWiki:Common.js"
From MakeICT Wiki
Jump to navigationJump to searchLine 2: | Line 2: | ||
(function () { | (function () { | ||
var cloneNodesToList = function(list, nodes) { | var cloneNodesToList = function(list, nodes) { | ||
− | + | if(nodes.length == 0){ | |
var listItem = document.createElement("li"); | var listItem = document.createElement("li"); | ||
− | listItem. | + | listItem.innerHTML = "None"; |
list.appendChild(listItem); | list.appendChild(listItem); | ||
+ | }else{ | ||
+ | for(var i=0; i<nodes.length; i++){ | ||
+ | var listItem = document.createElement("li"); | ||
+ | listItem.appendChild(nodes[i].cloneNode(true)); | ||
+ | list.appendChild(listItem); | ||
+ | } | ||
} | } | ||
}; | }; |
Revision as of 12:12, 8 March 2015
/* Any JavaScript here will be loaded for all users on every page load. */
(function () {
var cloneNodesToList = function(list, nodes) {
if(nodes.length == 0){
var listItem = document.createElement("li");
listItem.innerHTML = "None";
list.appendChild(listItem);
}else{
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);
}());