index.html 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Basic FileDrop example</title>
  6. <script type="text/javascript" src="filedrop-min.js"></script>
  7. <style type="text/css">
  8. /* Essential FileDrop zone element configuration: */
  9. .fd-zone {
  10. position: relative;
  11. overflow: hidden;
  12. /* The following are not required but create a pretty box: */
  13. width: 15em;
  14. margin: 0 auto;
  15. text-align: center;
  16. }
  17. /* Hides <input type="file"> while simulating "Browse" button: */
  18. .fd-file {
  19. opacity: 0;
  20. font-size: 118px;
  21. position: absolute;
  22. right: 0;
  23. top: 0;
  24. z-index: 1;
  25. padding: 0;
  26. margin: 0;
  27. cursor: pointer;
  28. filter: alpha(opacity=0);
  29. font-family: sans-serif;
  30. }
  31. /* Provides visible feedback when use drags a file over the drop zone: */
  32. .fd-zone.over { border-color: maroon; background: #eee; }
  33. </style>
  34. </head>
  35. <body>
  36. <noscript style="color: maroon">
  37. <h2>JavaScript is disabled in your browser. How do you expect FileDrop to work?</h2>
  38. </noscript>
  39. <h2 style="text-align: center">
  40. <a href="http://filedropjs.org">FileDrop</a> basic sample
  41. </h2>
  42. <!-- A FileDrop area. Can contain any text or elements, or be empty.
  43. Can be of any HTML tag too, not necessary fieldset. -->
  44. <fieldset id="zone">
  45. <legend>Drop a file inside&hellip;</legend>
  46. <p>Or click here to <em>Browse</em>..</p>
  47. <!-- Putting another element on top of file input so it overlays it
  48. and user can interact with it freely. -->
  49. <p style="z-index: 10; position: relative">
  50. <input type="checkbox" id="multiple">
  51. <label for="multiple">Allow multiple selection</label>
  52. </p>
  53. </fieldset>
  54. <script type="text/javascript">
  55. // Attach FileDrop to an area ('zone' is an ID but you can also give a DOM node):
  56. var zone = new FileDrop('zone', {});
  57. // Do something when a user chooses or drops a file:
  58. zone.event('send', function (files) {
  59. // Depending on browser support files (FileList) might contain multiple items.
  60. files.each(function (file) {
  61. // React on successful AJAX upload:
  62. file.event('done', function (xhr) {
  63. // 'this' here points to fd.File instance that has triggered the event.
  64. alert('Done uploading ' + this.name + ', response:\n\n' + xhr.responseText);
  65. });
  66. // Send the file:
  67. file.sendTo('ajax-upload');
  68. });
  69. });
  70. // A bit of sugar - toggling multiple selection:
  71. fd.addEvent(fd.byID('multiple'), 'change', function (e) {
  72. zone.multiple(e.currentTarget || e.srcElement.checked);
  73. });
  74. </script>
  75. </body>
  76. </html>