User:Mike Dillon/Scripts/defaultEditButton.js

// NOTE: This script doesn't work as expected, unfortunately.

// Overrides the "default" submit button on the edit form. // Does not work during preview or diff viewing of JavaScript editing.

/* */

var defaultEditButton;

addOnloadHook(function {    // Do nothing if defaultEditButton has not been set    if (!defaultEditButton) return;

// Find the form var editform = document.getElementById("editform"); if (!editform) return;

// Find the editButtons container var buttonsDiv = getElementsByClassName(editform, "div", "editButtons")[0]; if (!buttonsDiv) return;

// Find the submit form elements var buttons = buttonsDiv.getElementsByTagName("input"); if (!buttons) return;

// Unbold buttons var defaultButtonValue; for (var i = 0; i < buttons.length; i++) { if (buttons[i].name == defaultEditButton) { defaultButtonValue = buttons[i].value; buttons[i].style.fontWeight = "bold"; } else { buttons[i].style.fontWeight = "normal"; }   }

// Bad button name if (!defaultButtonValue) { alert("Bad defaultEditButton value: " + defaultEditButton); return; }

// Insert a dummy button to change the selected name to the default var dummy = document.createElement("input"); dummy.setAttribute("name", defaultEditButton); dummy.setAttribute("style", "display: none"); dummy.setAttribute("value", defaultButtonValue);

// Insert the dummy button as the first submit element in the form buttonsDiv.insertBefore(dummy, buttonsDiv.firstChild); });

/* */