MediaWiki:Gadget-protection-dropdown.js

From OpenWetWare

Jump to: navigation, search

Note - After saving, you may have to bypass your browser's cache to see the changes. Mozilla / Firefox / Safari: hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Command-R on a Macintosh); Konqueror: click Reload or press F5; Opera: clear the cache in Tools → Preferences; Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5.

// **********************************************************************
// **                 ***WARNING GLOBAL GADGET FILE***                 **
// **             changes to this file affect many users.              **
// **           please discuss on the talk page before editing         **
// **                                                                  **
// **********************************************************************
// Imported from: [[User:Steel359/^demon.js]]
// Version as of: 2007-07-01T00:27:43
// [[User:^demon/csd.js]] adapted for page protection use
 
// <pre><nowiki>
 
if (document.title.indexOf("Confirm protection") != -1) {
     var protform = {
				FillSelect:function(sel, arr){
					if(arr && arr.length>0){
						if(arr.length>1){
							var FirstOpt = new Option("Protection reasons", "");
							// catches stupid IE error
							if(FirstOpt.innerHTML != "Protection reasons"){
								FirstOpt.innerHTML = "Protection 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":"Edit warring","display":"Edit warring"},
					{"value":"Heavy IP vandalism","display":"IP vandalism"},
					{"value":"Linkspam","display":"Linkspam"},				
					{"value":"[[WP:BLP]] concerns","display":"WP:BLP concerns"},	
					{"value":"Evasion from blocked/banned user\(s\)","display":"Block/ban evasion"},
					{"value":"Pagemove war","display":"Move war"},
					{"value":"{{Unblock}} abuse","display":"Unblock abuse"},
					{"value":"High risk template","display":"High risk template"},
 
					{"value":"Unprotecting per [[WP:RFPP]] request","display":"Unprot per WP:RFPP"},
					{"value":"Page protected for a while\; hopefully protection is no longer necessary","display":"Time..."}
				],
 
				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('mwProtect-reason');
    			        // create select using included array
				var sel = document.createElement("SELECT");
				protform .FillSelect(sel, protform .ValueArray);
				// name it
				sel.name = "proOptions";
				sel.id = "proOptions";
                                sel.style.marginLeft = "10px";
                                protform .addEvent(sel, "change", protChangeBox, 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
				protform.addEvent(window, "load", addSelectAfter, false);
			}catch(err){}
}
 
function protChangeBox() {
                                                         var obj = document.getElementById('mwProtect-reason');
                                                         obj.value = document.getElementById('proOptions').value;
                                                         }
 
// ---------------------------------------------------------------------------------------------------------------
 
if (document.title.indexOf("Confirm protection") != -1) {
     var protform2 = {
				FillSelect:function(sel, arr){
					if(arr && arr.length>0){
						if(arr.length>1){
							var FirstOpt = new Option("Protection expiries", "");
							// catches stupid IE error
							if(FirstOpt.innerHTML != "Protection expiries"){
								FirstOpt.innerHTML = "Protection expiries";
							}
							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":"1 day","display":"1 day"},
					{"value":"2 days","display":"2 days"},
					{"value":"3 days","display":"3 days"},
					{"value":"5 days","display":"5 days"},
					{"value":"1 week","display":"1 week"},
					{"value":"2 weeks","display":"2 weeks"},
					{"value":"3 weeks","display":"3 weeks"},
					{"value":"4 weeks","display":"4 weeks"},
					{"value":"6 weeks","display":"6 weeks"}
				],
 
				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('expires');
    			        // create select using included array
				var sel = document.createElement("SELECT");
				protform2 .FillSelect(sel, protform2 .ValueArray);
				// name it
				sel.name = "proExpires";
				sel.id = "proExpires";
                                sel.style.marginLeft = "10px";
                                protform2 .addEvent(sel, "change", protChangeBox2, 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
				protform2.addEvent(window, "load", addSelectAfter, false);
			}catch(err){}
}
 
function protChangeBox2() {
                                                         var obj = document.getElementById('expires');
                                                         obj.value = document.getElementById('proExpires').value;
                                                         }
 
// </nowiki></pre>
Personal tools