User:Essjay/createsorter.js

/* */ // ======================================== // BEGIN Special:CreateWiki request sorter // ======================================== function sortCreateList { if(!document.getElementById('createwiki')) return var sel = document.getElementById('createwiki').req_id;

// sort var ln = sel.length; var req = new Array(sel.length); for(var i=0; i < ln; i++) { req[i] = sel.options[i].innerHTML + '@@@' + sel.options[i].value; req[i] = req[i].substring(0,1).toLowerCase + req[i].substring(1); } var sv = sel.value; var si = sel.selectedIndex; sel.innerHTML = ''; req.sort; var v = ''; var h = ''; for(var i=0; i < ln; i++) { v = req[i].substring(req[i].indexOf('@@@') + 3); h = req[i].substring(0, req[i].indexOf('@@@')); appendoption(v, h + ' (' + v + ')'); }

//jump: if loading a ticket, jump to that ticket if((document.getElementById('createwiki').load_id)&&(si == 0)) { if(document.getElementById('createwiki').wpCreateWikiName.value!='') { sel.value = document.getElementById('createwiki').load_id.value; } } else { //else, jump to previous location (if it wasn't just at the top) if(si == 0) { sel.selectedIndex = si; } else { sel.value = sv; } }

} addOnloadHook(sortCreateList);

function appendoption(value,inner) { var sel = document.getElementById('createwiki').req_id; var newopt = document.createElement('option'); newopt.value = value; newopt.text = inner; try { sel.add(newopt, null); } catch(ex) { sel.add(newopt); } } // ======================================== // END Special:CreateWiki request sorter // ======================================== /* */