-function protectInitialize(tableId, labelText) {
- if (document.createTextNode) {
- var box = document.getElementById(tableId);
- if (!box)
- return false;
-
- var tbody = box.getElementsByTagName('tbody')[0];
- var row = document.createElement('tr');
- tbody.appendChild(row);
-
- row.appendChild(document.createElement('td'));
- var col2 = document.createElement('td');
- row.appendChild(col2);
-
- var check = document.createElement('input');
- check.id = "mwProtectUnchained";
- check.type = "checkbox";
- check.addEventListener( 'click', protectChainUpdate, false );
- col2.appendChild(check);
-
- var space = document.createTextNode(" ");
- col2.appendChild(space);
-
- var label = document.createElement('label');
- label.setAttribute("for", "mwProtectUnchained");
- label.appendChild(document.createTextNode(labelText));
- col2.appendChild(label);
-
- if (protectAllMatch()) {
- check.checked = false;
- protectEnable(false);
- } else {
- check.checked = true;
- protectEnable(true);
- }
+function protectInitialize( tableId, labelText ) {
+ if( !( document.createTextNode && document.getElementById && document.getElementsByTagName ) )
+ return false;
- allowCascade();
-
- return true;
- }
- return false;
+ var box = document.getElementById( tableId );
+ if( !box )
+ return false;
+
+ var tbody = box.getElementsByTagName( 'tbody' )[0];
+ var row = document.createElement( 'tr' );
+ tbody.appendChild( row );
+
+ row.appendChild( document.createElement( 'td' ) );
+ var col = document.createElement( 'td' );
+ row.appendChild( col );
+
+ var check = document.createElement( 'input' );
+ check.id = 'mwProtectUnchained';
+ check.type = 'checkbox';
+ col.appendChild( check );
+ addClickHandler( check, protectChainUpdate );
+
+ col.appendChild( document.createTextNode( ' ' ) );
+ var label = document.createElement( 'label' );
+ label.setAttribute( 'for', 'mwProtectUnchained' );
+ label.appendChild( document.createTextNode( labelText ) );
+ col.appendChild( label );
+
+ check.checked = !protectAllMatch();
+ protectEnable( check.checked );
+
+ allowCascade();
+
+ return true;
}
function allowCascade() {
}
function protectUnchained() {
- var unchain = document.getElementById("mwProtectUnchained");
- if (!unchain) {
- alert("This shouldn't happen");
- return false;
- }
- return unchain.checked;
+ var unchain = document.getElementById( 'mwProtectUnchained' );
+ return unchain
+ ? unchain.checked
+ : true; // No control, so we need to let the user set both levels
}
function protectChain() {
}
}
+/**
+ * Add a click event handler to an element
+ *
+ * We use addEventListener() where available, otherwise
+ * we use a workaround to avoid breaking the chain
+ *
+ * @param Element element Element to add handler to
+ * @param callable handler Event handler callback
+ */
+function addClickHandler( element, handler ) {
+ if( window.addEventListener ) {
+ element.addEventListener( 'click', handler, false );
+ } else if( window.attachEvent ) {
+ element.attachEvent( 'onclick', handler );
+ }
+}
+
//note: all skins should call runOnloadHook() at the end of html output,
// so the below should be redundant. It's there just in case.
hookEvent("load", runOnloadHook);
-
-hookEvent("load", mwSetupToolbar);
+hookEvent("load", mwSetupToolbar);
\ No newline at end of file