tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

058.html (2869B)


      1 <!doctype html>
      2 <html>
      3  <head>
      4    <title>Dropping file into dropzone</title>
      5    <style type="text/css">
      6 span { display: inline-block; height: 100px; width: 100px; background: orange; }
      7 span + span { background: blue; }
      8    </style>
      9    <script type="text/javascript">
     10 window.onload = function () {
     11  var drag = document.getElementsByTagName('span')[0];
     12  drag.ondragstart = function (e) {
     13    e.dataTransfer.setData('text','PASS');
     14    e.dataTransfer.effectAllowed = 'copy';
     15    var filein = document.getElementsByTagName('input')[0];
     16    if( !filein.files ) {
     17      document.getElementsByTagName('p')[0].innerHTML = 'FAIL - file API is not supported.';
     18      return;
     19    }
     20    if( !filein.files[0] ) {
     21      document.getElementsByTagName('p')[0].innerHTML = 'FAIL - no file was found in the file input.';
     22      return;
     23    }
     24    var thefile = filein.files[0];
     25    try {
     26      e.dataTransfer.items.add(thefile);
     27    } catch(err) {
     28      document.getElementsByTagName('p')[0].innerHTML = 'FAIL - error when adding file';
     29      e.preventDefault();
     30      return;
     31    }
     32    if( e.dataTransfer.files.length != 1 ) {
     33      document.getElementsByTagName('p')[0].innerHTML = 'FAIL - file was not attached to data store';
     34      e.preventDefault();
     35      return;
     36    }
     37  };
     38  document.getElementsByTagName('span')[1].ondrop = function (e) {
     39    e.preventDefault();
     40    if( document.getElementsByTagName('p')[0].innerHTML ) { return; }
     41    if( e.dataTransfer.files.length != 1 ) {
     42      document.getElementsByTagName('p')[0].innerHTML = 'FAIL - file was not attached to data store during drop';
     43      e.preventDefault();
     44      return;
     45    }
     46    if( !window.FileReader ) {
     47      document.getElementsByTagName('p')[0].innerHTML = 'No FileReader constructor';
     48      e.preventDefault();
     49      return;
     50    }
     51    var reader = new FileReader();
     52    reader.onload = function () {
     53      if( !reader.result ) {
     54        document.getElementsByTagName('p')[0].innerHTML = 'No file data after load';
     55      } else if( !document.getElementsByTagName('p')[0].innerHTML ) {
     56        document.getElementsByTagName('p')[0].innerHTML = 'PASS';
     57      }
     58    };
     59    reader.readAsBinaryString(e.dataTransfer.files[0]);
     60    setTimeout(function () {
     61      if( !reader.result ) {
     62        document.getElementsByTagName('p')[0].innerHTML = 'No file data after timeout';
     63      }
     64    },1000);
     65  };
     66 };
     67    </script>
     68  </head>
     69  <body>
     70    <ol>
     71      <li>Select a non-empty plain text file on your computer using the following input: <input type="file"></li>
     72      <li>Drag the orange square onto the blue square and release it:<br><span draggable="true"></span> <span dropzone="copy file:text/plain"></span><br>
     73      If a prompt appears, accept it.</li>
     74      <li>Fail if new text does not appear below.</li>
     75    </ol>
     76    <p></p>
     77    <noscript><p>Enable JavaScript and reload</p></noscript>
     78  </body>
     79 </html>