User:Conrad.Irwin/searchtoggles.js

var myf=false;

function add_search_buttons{ myf= document.getElementById('powersearch');

if(!myf) return false; var fs = null; for(var i=0;i<myf.childNodes.length;i++){ if(myf.childNodes[i].nodeName.toUpperCase == 'FIELDSET') fs = myf.childNodes[i]; }

if(!fs) return false; create_search_toggle(fs,'check','Select all'); create_search_toggle(fs,'uncheck','Deselect all'); create_search_toggle(fs,'toggle','Invert selection'); } function create_search_toggle(frm,name,caption){ var sp = document.createElement('span'); var ln = document.createElement('a');

ln.appendChild(document.createTextNode(caption?caption:name)); try{ ln.addEventListener('click',function{toggle_search_buttons(name)},false); }catch(e){ ln.attachEvent('onclick',function{toggle_search_buttons(name)}); }

sp.appendChild(document.createTextNode('(')); sp.appendChild(ln);  sp.appendChild(document.createTextNode(') '));

frm.appendChild(sp); } function toggle_search_buttons(method){ if(!myf) return false;

var inputs = document.getElementsByTagName('input'); for(var i = 0;i<inputs.length; i++){ var mi = inputs[i]; if(mi.getAttribute('type').toUpperCase=='CHECKBOX'){ var s=mi.checked; if(!s && method != 'uncheck') { mi.checked='checked'; }else if(s && method != 'check') { mi.checked=''; }   }  } } if(wgPageName == 'Special:Search'){ addOnloadHook(add_search_buttons); }