SHARE
TWEET

Untitled

a guest Jun 23rd, 2014 213 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(function () {
  2.  
  3. var dropbox = $('#dropbox'),
  4.     message = $('.message', dropbox);
  5.  
  6. dropbox.filedrop({
  7.     paramname: 'pic',
  8.     maxfiles: 100,
  9.     maxfilesize: 100,
  10.     //url: '/Uploader.asmx/Upload',
  11.     url: '/Default.aspx',
  12.  
  13.     uploadFinished: function (i, file, response) {
  14.         $.data(file).addClass('done');
  15.         var count = file.size;
  16.         alert(count);
  17.     },
  18.  
  19.     error: function (err, file) {
  20.         switch (err) {
  21.             case 'BrowserNotSupported':
  22.                 showMessage('Your browser does not support HTML5 file uploads!');
  23.                 break;
  24.             case 'TooManyFiles':
  25.                 alert('Too many files! Please select 5 at most! (configurable)');
  26.                 break;
  27.             case 'FileTooLarge':
  28.                 alert(file.name + ' is too large! Please upload files up to 2mb (configurable).');
  29.                 break;
  30.             default:
  31.                 break;
  32.         }
  33.     },
  34.  
  35.     //Called before each upload is started
  36.     // beforeEach: function (file) {
  37.     //if (!file.type.match(/^image//)) {
  38.     //alert('Only images are allowed!');
  39.     //   alert(file.name);
  40.     // Returning false will cause the
  41.     // file to be rejected
  42.     //   return true;
  43.     // }
  44.     //},
  45.  
  46.     uploadStarted: function (i, file, len) {
  47.         createImage(file);
  48.  
  49.     },
  50.     progressUpdated: function (i, file, progress) {
  51.         $.data(file).find('.progress').width(progress);
  52.     }
  53.  
  54. });
  55.  
  56. var template = '<div class="preview">' +
  57.                     '<span class="imageHolder">' +
  58.                         '<img style="" />' +
  59.                         '<p class="background: rgba(0, 0, 0, 0.75);"></p>' +
  60.                         '<span class="uploaded"></span>' + // background: rgba(0, 0, 0, 0.75);
  61.                     '</span>' +
  62.                     '<div class="progressHolder">' +
  63.                         '<div class="progress"></div>' +
  64.                     '</div>' +
  65.                 '</div>';
  66.  
  67.  
  68. function createImage(file) {
  69.  
  70.     var preview = $(template),
  71.         image = $('img', preview),
  72.         paragraph = $('p', preview);
  73.  
  74.     var reader = new FileReader();
  75.  
  76.     image.width = 100;
  77.     image.height = 100;
  78.  
  79.     reader.onload = function (e) {
  80.  
  81.         // e.target.result holds the DataURL which
  82.         // can be used as a source of the image:
  83.         //alert(e.target.result);
  84.         //            $('p#filename').removeAttr('id');
  85.         //            $('p').attr('id', 'filename' + num + '');
  86.         //            $('p#filename').text(file.name);
  87.         paragraph.attr('id', 'filename').text(file.name);
  88.         image.attr('src', '../assets/img/fileicon.png');
  89.         num = num + 1;
  90.     };
  91.  
  92.     // Reading the file as a DataURL. When finished,
  93.     // this will trigger the onload function above:
  94.     reader.readAsDataURL(file);
  95.  
  96.     message.hide();
  97.     preview.appendTo(dropbox);
  98.  
  99.     // Associating a preview container
  100.     // with the file, using jQuery's $.data():
  101.  
  102.     $.data(file, preview);
  103. }
  104.  
  105. function showMessage(msg) {
  106.     message.html(msg);
  107. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top