1 function protectInitialize(tableId, labelText) {
2 if (document.createTextNode) {
3 var box = document.getElementById(tableId);
7 var tbody = box.getElementsByTagName('tbody')[0];
8 var row = document.createElement('tr');
9 tbody.appendChild(row);
11 row.appendChild(document.createElement('td'));
12 var col2 = document.createElement('td');
13 row.appendChild(col2);
15 var check = document.createElement('input');
16 check.id = "mwProtectUnchained";
17 check.type = "checkbox";
18 check.onclick = protectChainUpdate;
19 col2.appendChild(check);
21 var label = document.createElement('label');
22 label.setAttribute("for", "mwProtectUnchained");
23 label.appendChild(document.createTextNode(labelText));
24 col2.appendChild(label);
26 if (protectAllMatch()) {
27 check.checked = false;
39 function protectLevelsUpdate(source) {
40 if (!protectUnchained()) {
41 protectUpdateAll(source.selectedIndex);
45 function protectChainUpdate() {
46 if (protectUnchained()) {
55 function protectAllMatch() {
56 var values = new Array();
57 protectForSelectors(function(set) {
58 values[values.length] = set.selectedIndex;
60 for (var i = 1; i < values.length; i++) {
61 if (values[i] != values[0]) {
68 function protectUnchained() {
69 var unchain = document.getElementById("mwProtectUnchained");
71 alert("This shouldn't happen");
74 return unchain.checked;
77 function protectChain() {
78 // Find the highest-protected action and bump them all to this level
80 protectForSelectors(function(set) {
81 if (set.selectedIndex > maxIndex) {
82 maxIndex = set.selectedIndex;
85 protectUpdateAll(maxIndex);
88 function protectUpdateAll(index) {
89 protectForSelectors(function(set) {
90 if (set.selectedIndex != index) {
91 set.selectedIndex = index;
96 function protectForSelectors(func) {
97 var selectors = protectSelectors();
98 for (var i = 0; i < selectors.length; i++) {
103 function protectSelectors() {
104 var all = document.getElementsByTagName("select");
105 var ours = new Array();
106 for (var i = 0; i < all.length; i++) {
108 if (set.id.match(/^mwProtect-level-/)) {
109 ours[ours.length] = set;
115 function protectEnable(val) {
118 protectForSelectors(function(set) {
123 set.style.visible = val ? "visible" : "hidden";