From d7c506bc31b1fca413bc067735a4d702a10a8300 Mon Sep 17 00:00:00 2001 From: Ilmari Karonen Date: Mon, 15 Jan 2007 04:28:07 +0000 Subject: [PATCH] Make setupCheckboxShiftClick() process all checkboxes, not just those in ULs. This not only makes it more versatile, but it's faster too, since checkboxes tend to be much less common than list items. --- includes/DefaultSettings.php | 2 +- skins/common/wikibits.js | 77 +++++++++++++++--------------------- 2 files changed, 33 insertions(+), 46 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 46f9ce6046..2587413546 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -1105,7 +1105,7 @@ $wgCacheEpoch = '20030516000000'; * to ensure that client-side caches don't keep obsolete copies of global * styles. */ -$wgStyleVersion = '47'; +$wgStyleVersion = '48'; # Server-side caching: diff --git a/skins/common/wikibits.js b/skins/common/wikibits.js index 06a07d17f1..c6c8fc7c88 100644 --- a/skins/common/wikibits.js +++ b/skins/common/wikibits.js @@ -689,48 +689,35 @@ function addRightClickEditHandler(el) { } } +var checkboxes; +var lastCheckbox; + function setupCheckboxShiftClick() { - if (document.getElementsByTagName) { - var uls = document.getElementsByTagName('ul'); - var len = uls.length; - for (var i = 0; i < len; ++i) { - addCheckboxClickHandlers(uls[i]); - } - } + checkboxes = []; + lastCheckbox = null; + var inputs = document.getElementsByTagName('input'); + addCheckboxClickHandlers(inputs); } -function addCheckboxClickHandlers(ul, start, finish) { - if (ul.checkboxHandlersTimer) { - clearInterval(ul.checkboxHandlersTimer); - } - if ( !ul.childNodes ) { - return; - } - var len = ul.childNodes.length; - if (len < 2) { - return; - } - start = start || 0; - finish = finish || start + 250; - if ( finish > len ) { finish = len; } - ul.checkboxes = ul.checkboxes || []; - ul.lastCheckbox = ul.lastCheckbox || null; - for (var i = start; i inputs.length ) + finish = inputs.length; + + for ( var i = start; i < finish; i++ ) { + var cb = inputs[i]; + if ( !cb.type || cb.type.toLowerCase() != 'checkbox' ) + continue; + cb.index = checkboxes.push(cb) - 1; + cb.onmouseup = checkboxMouseupHandler; } - if (finish < len) { - var f=function(){ addCheckboxClickHandlers(ul, finish, finish+250); }; - ul.checkboxHandlersTimer=setInterval(f, 200); + + if ( finish < inputs.length ) { + setTimeout( function () { + addCheckboxClickHandlers(inputs, finish); + }, 200 ); } } @@ -738,8 +725,8 @@ function checkboxMouseupHandler(e) { if (typeof e == 'undefined') { e = window.event; } - if ( !e.shiftKey || this.container.lastCheckbox === null ) { - this.container.lastCheckbox = this.index; + if ( !e.shiftKey || lastCheckbox === null ) { + lastCheckbox = this.index; return true; } var endState = !this.checked; @@ -747,17 +734,17 @@ function checkboxMouseupHandler(e) { endState = !endState; } var start, finish; - if ( this.index < this.container.lastCheckbox ) { + if ( this.index < lastCheckbox ) { start = this.index + 1; - finish = this.container.lastCheckbox; + finish = lastCheckbox; } else { - start = this.container.lastCheckbox; + start = lastCheckbox; finish = this.index - 1; } for (var i = start; i <= finish; ++i ) { - this.container.checkboxes[i].checked = endState; + checkboxes[i].checked = endState; } - this.container.lastCheckbox = this.index; + lastCheckbox = this.index; return true; } -- 2.20.1