User:JLaTondre/csd.js

//

// This script augments MediaWiki:Sysop.js & MediaWiki:Deletereason-dropdown

if (wgAction == 'nondelete' && typeof(csdDeleteForm) == 'undefined') { var csdDeleteForm = { FillSelect:function(sel, arr){ if(arr && arr.length>0){ if(arr.length>1){ var FirstOpt = new Option("CSD Reasons", ""); // catches stupid IE error if(FirstOpt.innerHTML != "CSD Reasons"){ FirstOpt.innerHTML = "CSD Reasons"; }         sel.appendChild(FirstOpt); sel.options[0].style.color = "gray" }       sel.disabled = false; for(var i=0;i<arr.length;i++){ var opt = new Option(arr[i].display, arr[i].value); // catches stupid IE error if(opt.innerHTML != arr[i].display){ opt.innerHTML = arr[i].display; }         sel.appendChild(opt); }     }else{ sel.options[0] = new Option("No Options Available", ""); // catches stupid IE error if(sel.options[0].innerHTML != "No Options Available"){ sel.options[0].innerHTML = "No Options Available"; }       sel.disabled = true; return false; }     return true; },   ValueArray:[ {"value":"","display":""}, {"value":"CSD R2: Redirect to User/User talk namespaces from mainspace","display":"R2 - Crossnamespace"}, {"value":"AFD: Deleted after discussion at Articles for Deletion","display":"AFD close"}, {"value":"RFD: Deleted after discussion at Redirects for Discussion","display":"RFD close"} ],   //**************************** attaching function ***************************************** // got thIS super handi function from http://www.scottandrew.com he is pretty dang smart ** //*****************************************************************************************   addEvent:function(obj, evType, fn, useCapture){ //alert(obj); if (obj.addEventListener){ obj.addEventListener(evType, fn, useCapture); return true; } else if (obj.attachEvent){ var r = obj.attachEvent("on"+evType, fn); return r;     } else { alert("Handler could not be attached"); }   }  }  function addSelectAfter{ var obj = document.getElementById('wpReason'); // create select using included array var sel = document.createElement("SELECT"); csdDeleteForm .FillSelect(sel, csdDeleteForm .ValueArray); // name it   sel.name = "csdOptions"; sel.id = "csdOptions"; sel.style.marginLeft = "10px"; csdDeleteForm .addEvent(sel, "change", csdChangeBox, false); // check for next sibling and insert before it or at the end if(obj.nextSibling){ obj.parentNode.insertBefore(sel,obj.nextSibling); }else{ obj.parentNode.appendChild(sel); } }  try{ // add one on load csdDeleteForm.addEvent(window, "load", addSelectAfter, false); }catch(err){} }

function csdChangeBox { var obj = document.getElementById('wpReason'); obj.value = document.getElementById('csdOptions').value; }

//