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.

This commit is contained in:
Ilmari Karonen 2007-01-15 04:28:07 +00:00
parent 3ead3cb165
commit d7c506bc31
2 changed files with 33 additions and 46 deletions

View file

@ -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:

View file

@ -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);
function addCheckboxClickHandlers(inputs, start) {
if ( !start) start = 0;
var finish = start + 250;
if ( finish > 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 ( !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<finish; ++i) {
var child = ul.childNodes[i];
if ( child && child.childNodes && child.childNodes[0] ) {
var cb = child.childNodes[0];
if ( !cb.nodeName || cb.nodeName.toLowerCase() != 'input' ||
!cb.type || cb.type.toLowerCase() != 'checkbox' ) {
return;
}
cb.index = ul.checkboxes.push(cb) - 1;
cb.container = ul;
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;
}