User:Evad37/CatVision.js

//initial setup var $cats_ul = $('#mw-normal-catlinks ul');                      //get list var $cats_li = $cats_ul.children('li');                          //get list items var catlist = '';                                                //will contain a list of all cats on page $cats_li.each(function( index ) {                                //add sequential ids to items so default order can be restored    if (index < 10) {        var position = '00' + index;    } else if (index < 100) {          var position = '0' + index;    } else {        var position = index;    }    $( this ).prop( "id", position );    var pipe_if_needed = (index == 0) ? '' : '%7C';                  catlist = catlist + pipe_if_needed + 'Category:' + $(this).text; //build up list of cats });

$('#mw-normal-catlinks').wrap(" ");    //wrap with div - columns will be turned on/off by setting style here

//main functions function cat_sort_alpha { $cats_li.sort(function(a,b) {       if(a.children[0].textContent > b.children[0].textContent) return 1;        return -1;    }); $cats_li.detach.prependTo($cats_ul); }

function cat_sort_orig { $cats_li.sort(function(a,b) {       if(a.getAttribute("id") > b.getAttribute("id")) return 1;        return -1;    }); $cats_li.detach.prependTo($cats_ul); }

function cat_show_cols { $('#catColWrap').attr("style", "-moz-column-width: 30em; -webkit-column-width: 30em; column-width: 30em;"); $('#catColWrap > div > ul > li').attr("style", "display:block;"); }

function cat_no_cols { $('#catColWrap').attr("style", ""); $('#catColWrap > div > ul > li').attr("style", ""); }

//interface var catvision_links = "Show in columns Sort alphabetical "; $('#catlinks').prepend(catvision_links);

function toggle_cols { if ($('#check_cols').prop( "checked" )) { cat_show_cols; } else { cat_no_cols; } }

function toggle_sort { if ($('#check_sort').prop( "checked" )) { cat_sort_alpha; } else { cat_sort_orig; } }