sort
This commit is contained in:
parent
8ac7c29b2d
commit
399c6749c8
39
js/main.js
39
js/main.js
|
|
@ -47,6 +47,8 @@ function loadHTML() {
|
|||
console.log(id + " allready exists!")
|
||||
return
|
||||
|
||||
|
||||
|
||||
}
|
||||
$("#tocraft")
|
||||
.append(
|
||||
|
|
@ -71,6 +73,11 @@ function loadHTML() {
|
|||
});
|
||||
$("#" + tagid).val(1)
|
||||
})
|
||||
$("#menu li ul").each(function(){
|
||||
$(this).html($(this).children('li').sort(function(a, b){
|
||||
return ($(b).data('position')) < ($(a).data('position')) ? 1 : -1;
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
function loadJSON(itemname) {
|
||||
|
|
@ -125,6 +132,8 @@ $(document)
|
|||
+ " allready exists!")
|
||||
return
|
||||
|
||||
|
||||
|
||||
}
|
||||
$("#tocraft")
|
||||
.append(
|
||||
|
|
@ -255,3 +264,33 @@ function updateoutput() {
|
|||
}
|
||||
})
|
||||
}
|
||||
|
||||
function sortUnorderedList(ul, sortDescending) {
|
||||
if (typeof ul == "string")
|
||||
ul = document.getElementById(ul);
|
||||
|
||||
// Idiot-proof, remove if you want
|
||||
if (!ul) {
|
||||
alert("The UL object is null!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the list items and setup an array for sorting
|
||||
var lis = ul.getElementsByTagName("LI");
|
||||
var vals = [];
|
||||
|
||||
// Populate the array
|
||||
for (var i = 0, l = lis.length; i < l; i++)
|
||||
vals.push(lis[i].innerHTML);
|
||||
|
||||
// Sort it
|
||||
vals.sort();
|
||||
|
||||
// Sometimes you gotta DESC
|
||||
if (sortDescending)
|
||||
vals.reverse();
|
||||
|
||||
// Change the list on the page
|
||||
for (var i = 0, l = lis.length; i < l; i++)
|
||||
lis[i].innerHTML = vals[i];
|
||||
}
|
||||
Loading…
Reference in New Issue