| 1 |
|
| 2 |
// Declare big lookup globally to avoid doing them too often
|
| 3 |
|
| 4 |
var all_inputs = document.getElementsByTagName('input');
|
| 5 |
|
| 6 |
/**
|
| 7 |
* Attaches the toggletree behaviour to container checkboxes.
|
| 8 |
*/
|
| 9 |
function toggleTreeAutoAttach() {
|
| 10 |
for (var c = 0; c < all_inputs.length; c++)
|
| 11 |
{
|
| 12 |
var input_node = all_inputs[c];
|
| 13 |
if(! hasClass(input_node, 'filebrowser_checkbox')) continue;
|
| 14 |
|
| 15 |
// the checkbox may not know if it's a container, that's a property of the row
|
| 16 |
var td = input_node.parentNode;
|
| 17 |
var tr = td.parentNode;
|
| 18 |
tr.onclick = toggle_row;
|
| 19 |
|
| 20 |
// disable normal activity, row clicking handles it now
|
| 21 |
input_node.onclick = function() {this.checked = ! this.checked; }
|
| 22 |
input_node.onchange = enhance_container;
|
| 23 |
input_node.onchange(); // Do it now to reflect any browser-cached form status
|
| 24 |
|
| 25 |
if (hasClass(tr, 'container')) {
|
| 26 |
input_node.onchange = toggle_tree_children;
|
| 27 |
}
|
| 28 |
}
|
| 29 |
}
|
| 30 |
|
| 31 |
if (isJsEnabled()) {
|
| 32 |
addLoadEvent(toggleTreeAutoAttach);
|
| 33 |
}
|
| 34 |
|
| 35 |
/**
|
| 36 |
* Handler for a container checkbox onclick
|
| 37 |
* Every box turn on!
|
| 38 |
*/
|
| 39 |
function toggle_tree_children(e){
|
| 40 |
var id = this.id;
|
| 41 |
if(typeof(setCheckboxes) == 'function') // setCheckboxes may be supplied by tweakUI library. If not, no biggie.
|
| 42 |
setCheckboxes( id+"_contents", this.checked ); // used for the table structure - associated element, not the current one.
|
| 43 |
this.enhance = enhance_container; this.enhance();
|
| 44 |
|
| 45 |
if(window.event) window.event.cancelBubble = true;
|
| 46 |
if(e){e.stopPropagation();}
|
| 47 |
return false
|
| 48 |
}
|
| 49 |
|
| 50 |
/*
|
| 51 |
* As well as just toggling the checkbox, toggle the css class of this boxes label
|
| 52 |
* For great brightness!
|
| 53 |
* Should work on either table TRs or list LIs
|
| 54 |
*/
|
| 55 |
function toggle_row(e) {
|
| 56 |
var checkbox = this.getElementsByTagName( 'input' )[0];
|
| 57 |
var turn_on = (! checkbox.checked);
|
| 58 |
|
| 59 |
checkbox.setAttribute('checked',turn_on); // dom/ie
|
| 60 |
checkbox.checked = turn_on; // dhtml/moz
|
| 61 |
if(checkbox.onchange)checkbox.onchange();
|
| 62 |
|
| 63 |
if(window.event) window.event.cancelBubble = true;
|
| 64 |
if(e){e.stopPropagation();}
|
| 65 |
}
|
| 66 |
|
| 67 |
function enhance_container(){
|
| 68 |
var p = this.parentNode;
|
| 69 |
while(p && (p.nodeName != 'TR') && (p.nodeName != 'LI')) p = p.parentNode;
|
| 70 |
if(p){enhance_row_visually(p)}
|
| 71 |
}
|
| 72 |
|
| 73 |
function enhance_row_visually(row){
|
| 74 |
var checkbox = row.getElementsByTagName( 'input' )[0];
|
| 75 |
if(!checkbox){return};
|
| 76 |
|
| 77 |
if (checkbox.checked ) {
|
| 78 |
addClass(row, 'marked');
|
| 79 |
} else {
|
| 80 |
removeClass(row, 'marked');
|
| 81 |
}
|
| 82 |
}
|