script.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /**
  2. * FancyUpload Showcase
  3. *
  4. * @license MIT License
  5. * @author Harald Kirschner <mail [at] digitarald [dot] de>
  6. * @copyright Authors
  7. */
  8. window.addEvent('domready', function() {
  9. var link = $('select-0');
  10. var linkIdle = link.get('html');
  11. function linkUpdate() {
  12. var l = swf.fileList.length;
  13. if (!l) {
  14. link.title = null;
  15. link.set('html', linkIdle);
  16. return;
  17. }
  18. var rate = Swiff.Uploader.formatUnit(swf.rate, 'bps');
  19. var size = Swiff.Uploader.formatUnit(swf.size, 'b');
  20. var bytesLoaded = Swiff.Uploader.formatUnit(swf.bytesLoaded, 'b');
  21. link.set('html', l + ' Upload' + ((l != 1) ? 's' : '') + ' (' + swf.percentLoaded + '%)');
  22. link.title = bytesLoaded + ' of ' + rate + ' with ' + bytesLoaded;
  23. }
  24. /**
  25. * Uploader instance
  26. */
  27. var swf = new Swiff.Uploader({
  28. path: '../../source/Swiff.Uploader.swf',
  29. url: '../script.php',
  30. verbose: true,
  31. queued: false,
  32. target: link,
  33. instantStart: true,
  34. onSelectSuccess: function() {
  35. if (Browser.Platform.linux) window.alert('Warning: Due to a misbehaviour of Adobe Flash Player on Linux,\nthe browser will probably freeze during the upload process.\nSince you are prepared now, the upload will start right away ...');
  36. },
  37. onQueue: linkUpdate,
  38. onFileComplete: function(file) {
  39. if (file.response.error) alert('Upload failed, please try again (' + file.response.error + ' ' + file.response.code + ').');
  40. console.log('Server response:', file.response);
  41. file.remove();
  42. }
  43. });
  44. /**
  45. * Button state
  46. */
  47. link.addEvents({
  48. click: function() {
  49. return false;
  50. },
  51. mouseenter: function() {
  52. this.addClass('hover');
  53. swf.reposition();
  54. },
  55. mouseleave: function() {
  56. this.removeClass('hover');
  57. this.blur();
  58. },
  59. mousedown: function() {
  60. this.focus();
  61. }
  62. });
  63. });