Changes

Jump to navigation Jump to search

MediaWiki:Common.js

885 bytes added, 5 years ago
Add sorting of CatTree
}
});
// CategoryTree Sorting
var container = $( $( "div.CategoryTreeSection" ).first().children().last()[0] ),
items = container.children();
 
items.sort( function(a, b){
if( $( a ).find(".CategoryTreeLabelNs14").length === 0){
return 0;
}
 
// Get text of the category link
firstText = $(a).find("a").text();
secondText = $(b).find("a").text();
 
// Regex to get the cohort year
firstMatch = /(\d{4})/ig.exec( firstText.trim() );
secondMatch = /(\d{4})/ig.exec( secondText.trim() );
 
// If nothing is found, status will remain same
if( firstMatch === null && secondMatch === null ) {
return 0;
}
 
// If first element match
if( firstMatch !== null) {
if( secondMatch !== null ){
return firstMatch[1] > secondMatch[1] ? -1 : 1;
} else {
return -1;
}
} else {
return secondMatch !== null ? 1 : 0;
}
});
container.append( items );
});
 
// Sidebar

Navigation menu