From 34db63e0a0b13bb1afc68dd579993e8980d517c8 Mon Sep 17 00:00:00 2001 From: Rob Church Date: Sun, 29 Jul 2007 14:32:26 +0000 Subject: [PATCH] (bug 10732 and others) Further fixes to protect chaining JavaScript; introduce addClickHandler() to work around missing addEventListener() in IE and other browsers that suck --- includes/DefaultSettings.php | 2 +- skins/common/protect.js | 83 ++++++++++++++++-------------------- skins/common/wikibits.js | 20 ++++++++- 3 files changed, 56 insertions(+), 49 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index f6b91234fc..1996376e0d 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -1195,7 +1195,7 @@ $wgCacheEpoch = '20030516000000'; * to ensure that client-side caches don't keep obsolete copies of global * styles. */ -$wgStyleVersion = '91'; +$wgStyleVersion = '92'; # Server-side caching: diff --git a/skins/common/protect.js b/skins/common/protect.js index 7691eba07c..a2ebcd7f31 100644 --- a/skins/common/protect.js +++ b/skins/common/protect.js @@ -1,44 +1,37 @@ -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() { @@ -90,12 +83,10 @@ function protectAllMatch() { } 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() { diff --git a/skins/common/wikibits.js b/skins/common/wikibits.js index af3ffc6326..0aef60a9e8 100644 --- a/skins/common/wikibits.js +++ b/skins/common/wikibits.js @@ -1302,8 +1302,24 @@ function runOnloadHook() { } } +/** + * 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 -- 2.20.1