/***************************************************************************\ * * * please modify this file and leave plenty of comments. when done, please * * visit http://dean.edwards.name/packer/ to compress this and place the * * compressed output in the loaded version of this file * * * \***************************************************************************/ // Multiple file selector by Stickman -- http://www.the-stickman.com function MultiSelector( list_target, max ){ this.list_target = list_target; this.count = 0; this.id = 0; if( max ){ this.max = max; } else { this.max = -1; }; // BitMod Added addNamedElement function to allow us to name these. // Thus we can have multiple on the same form this.addNamedElement = function(element, name) { if( element.tagName == 'INPUT' && element.type == 'file' ){ element.base_name = name; element.name = name + '_' + this.id++; element.multi_selector = this; element.onchange = function(){ var new_element = document.createElement( 'input' ); new_element.type = 'file'; this.parentNode.insertBefore( new_element, this ); this.multi_selector.addNamedElement( new_element, element.base_name); this.multi_selector.addListRow( this ); this.style.position = 'absolute'; this.style.left = '-1000px'; }; if( this.max != -1 && this.count >= this.max ){ element.disabled = true; }; this.count++; this.current_element = element; } else { alert( 'Error: not a file input element' ); }; }; this.addElement = function( element ){ this.addNamedElement(element, 'file'); }; this.addListRow = function( element ){ var new_row = document.createElement( 'div' ); var new_row_button = document.createElement( 'input' ); new_row_button.type = 'button'; new_row_button.value = 'Remove'; new_row.element = element; new_row_button.onclick= function(){ this.parentNode.element.parentNode.removeChild( this.parentNode.element ); this.parentNode.parentNode.removeChild( this.parentNode ); this.parentNode.element.multi_selector.count--; this.parentNode.element.multi_selector.current_element.disabled = false; return false; }; new_row.innerHTML = ''+element.value+''; new_row.appendChild( new_row_button ); this.list_target.appendChild( new_row ); }; };