}
}
+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<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;
- }
+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 (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 );
}
}
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;
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;
}