events.html 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <!DOCTYPE html>
  2. <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
  3. <head>
  4. <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
  5. <title>Plupload - Events example</title>
  6. <!-- production -->
  7. <script type="text/javascript" src="../js/plupload.full.min.js"></script>
  8. <!-- debug
  9. <script type="text/javascript" src="../js/moxie.js"></script>
  10. <script type="text/javascript" src="../js/plupload.dev.js"></script>
  11. -->
  12. </head>
  13. <body style="font: 13px Verdana; background: #eee; color: #333">
  14. <h1>Events example</h1>
  15. <div id="container">
  16. <a id="pickfiles" href="javascript:;">[Select files]</a>
  17. <a id="uploadfiles" href="javascript:;">[Upload files]</a>
  18. </div>
  19. <br />
  20. <pre id="console"></pre>
  21.  
  22. <script type="text/javascript">
  23. var uploader = new plupload.Uploader({
  24.         // General settings
  25.         runtimes : 'silverlight,html4',
  26. browse_button : 'pickfiles', // you can pass in id...
  27.         url : 'upload.php',
  28.         chunk_size : '1mb',
  29.         unique_names : true,
  30.  
  31.         // Resize images on client-side if we can
  32.         resize : { width : 320, height : 240, quality : 90 },
  33.         
  34.         filters : {
  35.             max_file_size : '10mb',
  36. // Specify what files to browse for
  37.             mime_types: [
  38.                 {title : "Image files", extensions : "jpg,gif,png"},
  39.                 {title : "Zip files", extensions : "zip"}
  40.             ]
  41.         },
  42.  
  43. flash_swf_url : '../js/Moxie.swf',
  44. silverlight_xap_url : '../js/Moxie.xap',
  45.          
  46.         // PreInit events, bound before the internal events
  47.         preinit : {
  48.             Init: function(up, info) {
  49.                 log('[Init]', 'Info:', info, 'Features:', up.features);
  50.             },
  51.  
  52.             UploadFile: function(up, file) {
  53.                 log('[UploadFile]', file);
  54.  
  55.                 // You can override settings before the file is uploaded
  56.                 // up.setOption('url', 'upload.php?id=' + file.id);
  57.                 // up.setOption('multipart_params', {param1 : 'value1', param2 : 'value2'});
  58.             }
  59.         },
  60.  
  61.         // Post init events, bound after the internal events
  62.         init : {
  63. PostInit: function() {
  64. // Called after initialization is finished and internal event handlers bound
  65. log('[PostInit]');
  66. document.getElementById('uploadfiles').onclick = function() {
  67. uploader.start();
  68. return false;
  69. };
  70. },
  71. Browse: function(up) {
  72.                 // Called when file picker is clicked
  73.                 log('[Browse]');
  74.             },
  75.             Refresh: function(up) {
  76.                 // Called when the position or dimensions of the picker change
  77.                 log('[Refresh]');
  78.             },
  79.  
  80.             StateChanged: function(up) {
  81.                 // Called when the state of the queue is changed
  82.                 log('[StateChanged]', up.state == plupload.STARTED ? "STARTED" : "STOPPED");
  83.             },
  84.  
  85.             QueueChanged: function(up) {
  86.                 // Called when queue is changed by adding or removing files
  87.                 log('[QueueChanged]');
  88.             },
  89. OptionChanged: function(up, name, value, oldValue) {
  90. // Called when one of the configuration options is changed
  91. log('[OptionChanged]', 'Option Name: ', name, 'Value: ', value, 'Old Value: ', oldValue);
  92. },
  93. BeforeUpload: function(up, file) {
  94. // Called right before the upload for a given file starts, can be used to cancel it if required
  95. log('[BeforeUpload]', 'File: ', file);
  96. },
  97.  
  98.             UploadProgress: function(up, file) {
  99.                 // Called while file is being uploaded
  100.                 log('[UploadProgress]', 'File:', file, "Total:", up.total);
  101.             },
  102. FileFiltered: function(up, file) {
  103. // Called when file successfully files all the filters
  104.                 log('[FileFiltered]', 'File:', file);
  105. },
  106.  
  107.             FilesAdded: function(up, files) {
  108.                 // Called when files are added to queue
  109.                 log('[FilesAdded]');
  110.  
  111.                 plupload.each(files, function(file) {
  112.                     log('  File:', file);
  113.                 });
  114.             },
  115.  
  116.             FilesRemoved: function(up, files) {
  117.                 // Called when files are removed from queue
  118.                 log('[FilesRemoved]');
  119.  
  120.                 plupload.each(files, function(file) {
  121.                     log('  File:', file);
  122.                 });
  123.             },
  124.  
  125.             FileUploaded: function(up, file, info) {
  126.                 // Called when file has finished uploading
  127.                 log('[FileUploaded] File:', file, "Info:", info);
  128.             },
  129.  
  130.             ChunkUploaded: function(up, file, info) {
  131.                 // Called when file chunk has finished uploading
  132.                 log('[ChunkUploaded] File:', file, "Info:", info);
  133.             },
  134. UploadComplete: function(up, files) {
  135. // Called when all files are either uploaded or failed
  136.                 log('[UploadComplete]');
  137. },
  138. Destroy: function(up) {
  139. // Called when uploader is destroyed
  140.                 log('[Destroy] ');
  141. },
  142.  
  143.             Error: function(up, args) {
  144.                 // Called when error occurs
  145.                 log('[Error] ', args);
  146.             }
  147.         }
  148.     });
  149.  
  150.  
  151.     function log() {
  152.         var str = "";
  153.  
  154.         plupload.each(arguments, function(arg) {
  155.             var row = "";
  156.  
  157.             if (typeof(arg) != "string") {
  158.                 plupload.each(arg, function(value, key) {
  159.                     // Convert items in File objects to human readable form
  160.                     if (arg instanceof plupload.File) {
  161.                         // Convert status to human readable
  162.                         switch (value) {
  163.                             case plupload.QUEUED:
  164.                                 value = 'QUEUED';
  165.                                 break;
  166.  
  167.                             case plupload.UPLOADING:
  168.                                 value = 'UPLOADING';
  169.                                 break;
  170.  
  171.                             case plupload.FAILED:
  172.                                 value = 'FAILED';
  173.                                 break;
  174.  
  175.                             case plupload.DONE:
  176.                                 value = 'DONE';
  177.                                 break;
  178.                         }
  179.                     }
  180.  
  181.                     if (typeof(value) != "function") {
  182.                         row += (row ? ', ' : '') + key + '=' + value;
  183.                     }
  184.                 });
  185.  
  186.                 str += row + " ";
  187.             } else {
  188.                 str += arg + " ";
  189.             }
  190.         });
  191.  
  192.         var log = document.getElementById('console');
  193.         log.innerHTML += str + "\n";
  194.     }
  195. uploader.init();
  196. </script>
  197. </body>
  198. </html>