1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| $(document).ready(function() { var dropbox = document.getElementById("dropper"); dropbox.addEventListener("dragover", dragOver, false); dropbox.addEventListener("drop", drop, false); });
function dragOver(evt) { evt.stopPropagation(); evt.preventDefault(); }
function drop(evt) { evt.stopPropagation(); evt.preventDefault(); var files = evt.dataTransfer.files; if (files.length > 0) handleFiles(files); }
function handleFiles(files) { var f = files[0]; var output = []; output.push('<strong>', f.name, '</strong> (', f.type || 'n/a', ') - ', f.size, ' bytes'); $("#fileinfo").html(output.join(""));
var reader = new FileReader(); reader.onloadend = handleReaderLoadEnd; reader.readAsText(f); }
function handleReaderLoadEnd(evt) { lines = evt.target.result.split(/\r\n|\r|\n/); coords = []; for(i=0; i < lines.length; i++) { var line = lines[i].split(","); if (line.length > 1 && !isNaN(line[0]) && !isNaN(line[1])) { coords[coords.length]= line[0] + "," + line[1]; } } $("#filedata").empty(); $.each(coords, function(index, value){ $("#filedata").append(value + "<br />"); }); }
|