function handleFileSelected(e) {
    //console.log(e.target.files);
    var singleFile = e.target.files[0];
    var url = URL.createObjectURL(singleFile);
    uploadedFile = singleFile;
    // figure out the variable name to use - remove the file extension, and replace any characters not allowed in a variable name
    variableName = uploadedFile.name.replace(/\.[^/.]+$/, "").replace(/[^a-zA-Z0-9_]+/g, '_');
    // variable names can't begin with a number
    var rx = new RegExp(/^[0-9]*$/gm);
    if (rx.test(variableName)) {
        variableName = '_' + variableName;
    }
    // the above rules should create a variable name valid for most languages
    
    init();

    imgImageHolder = null;
    binBinaryFileHolder = null;

    // display the file info
    $('#fiName').text(singleFile.name);
    $('#fiSize').text(singleFile.size + ' byte(s)');
    $('#fiType').text(singleFile.type || (singleFile.name.substr(singleFile.name.lastIndexOf('.'))));
    $('#fiLastModifiedDate').text(new Date(singleFile.lastModified).toISOString());
    // show the conversion options fieldset
    $('#fsConversionOptions').show();
    $('#btnConvert').show();
    setStatus('ready!');

    if (isImage(singleFile.type)) {
        console.log('file is an image');
        // if this is an image, show the apropriate stuff
        $('.fileIsImage').show();
        // along with the preview image
        imgImageHolder = new Image();
        imgImageHolder.src = url;
        imgImageHolder.onload = function () {
            //URL.revokeObjectURL(this.src);
            var imgPreview = imgImageHolder.cloneNode(true);
            imgPreview.id = 'imgPreview';
            imgPreview.alt = 'Preview of ' + singleFile.name;
            $('#imgPreview').remove();
            $('#divPreview').append(imgPreview);
            $('#fiSize').text($('#fiSize').text() + ' (' + imgImageHolder.width + 'x' + imgImageHolder.height + 'px)');
        }
    }
    else {
        console.log('file is binary');
    }
    // load the file as binary too
    var reader = new FileReader();
    reader.onload = function (e) {
        binBinaryFileHolder = e.target.result;
    }
    reader.readAsArrayBuffer(singleFile);
}
/**
 * Handles when a file is selected by the user.
 * Displays the file info.
 */
Handles when a file is selected by the user.
Displays the file info.
Handles when a file is selected by the user . Displays the file info .
function handleFileSelected(e) {
    var singleFile = e.target.files[0];
    var url = URL.createObjectURL(singleFile);
    uploadedFile = singleFile;
    variableName = uploadedFile.name.replace(/\.[^/.]+$/, "").replace(/[^a-zA-Z0-9_]+/g, '_');
    var rx = new RegExp(/^[0-9]*$/gm);
    if (rx.test(variableName)) {
        variableName = '_' + variableName;
    }
    init();
    imgImageHolder = null;
    binBinaryFileHolder = null;
    $('#fiName').text(singleFile.name);
    $('#fiSize').text(singleFile.size + ' byte(s)');
    $('#fiType').text(singleFile.type || (singleFile.name.substr(singleFile.name.lastIndexOf('.'))));
    $('#fiLastModifiedDate').text(new Date(singleFile.lastModified).toISOString());
    $('#fsConversionOptions').show();
    $('#btnConvert').show();
    setStatus('ready!');
    if (isImage(singleFile.type)) {
        console.log('file is an image');
        $('.fileIsImage').show();
        imgImageHolder = new Image();
        imgImageHolder.src = url;
        imgImageHolder.onload = function () {
            var imgPreview = imgImageHolder.cloneNode(true);
            imgPreview.id = 'imgPreview';
            imgPreview.alt = 'Preview of ' + singleFile.name;
            $('#imgPreview').remove();
            $('#divPreview').append(imgPreview);
            $('#fiSize').text($('#fiSize').text() + ' (' + imgImageHolder.width + 'x' + imgImageHolder.height + 'px)');
        }
    }
    else {
        console.log('file is binary');
    }
    var reader = new FileReader();
    reader.onload = function (e) {
        binBinaryFileHolder = e.target.result;
    }
    reader.readAsArrayBuffer(singleFile);
}
function handleFileSelected ( e ) { var singleFile = e . target . files [ 0 ] ; var url = URL . createObjectURL ( singleFile ) ; uploadedFile = singleFile ; variableName = uploadedFile . name . replace ( / \.[^/.]+$ / , "" ) . replace ( / [^a-zA-Z0-9_]+ / g , '_' ) ; var rx = new RegExp ( / ^[0-9]*$ / gm ) ; if ( rx . test ( variableName ) ) { variableName = '_' + variableName ; } init ( ) ; imgImageHolder = null ; binBinaryFileHolder = null ; $ ( '#fiName' ) . text ( singleFile . name ) ; $ ( '#fiSize' ) . text ( singleFile . size + ' byte(s)' ) ; $ ( '#fiType' ) . text ( singleFile . type || ( singleFile . name . substr ( singleFile . name . lastIndexOf ( '.' ) ) ) ) ; $ ( '#fiLastModifiedDate' ) . text ( new Date ( singleFile . lastModified ) . toISOString ( ) ) ; $ ( '#fsConversionOptions' ) . show ( ) ; $ ( '#btnConvert' ) . show ( ) ; setStatus ( 'ready!' ) ; if ( isImage ( singleFile . type ) ) { console . log ( 'file is an image' ) ; $ ( '.fileIsImage' ) . show ( ) ; imgImageHolder = new Image ( ) ; imgImageHolder . src = url ; imgImageHolder . onload = function ( ) { var imgPreview = imgImageHolder . cloneNode ( true ) ; imgPreview . id = 'imgPreview' ; imgPreview . alt = 'Preview of ' + singleFile . name ; $ ( '#imgPreview' ) . remove ( ) ; $ ( '#divPreview' ) . append ( imgPreview ) ; $ ( '#fiSize' ) . text ( $ ( '#fiSize' ) . text ( ) + ' (' + imgImageHolder . width + 'x' + imgImageHolder . height + 'px)' ) ; } } else { console . log ( 'file is binary' ) ; } var reader = new FileReader ( ) ; reader . onload = function ( e ) { binBinaryFileHolder = e . target . result ; } reader . readAsArrayBuffer ( singleFile ) ; }
Handles when a file is selected by the user.
Handles when a file is selected by the user .
//console.log(e.target.files); // figure out the variable name to use - remove the file extension, and replace any characters not allowed in a variable name // variable names can't begin with a number // the above rules should create a variable name valid for most languages // display the file info // show the conversion options fieldset // if this is an image, show the apropriate stuff // along with the preview image //URL.revokeObjectURL(this.src); // load the file as binary too