universal_s3_uploader 0.1.7 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 5f3de3b3418998a1d58ed9cd4612a7a664abba28
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 37537e2dd4809a839a41b7c1c8d5d4d367d0c38f
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: ad78edcf06e8d0978589ebbf7c117d95850c4dd12695019ef46d6122e95032b046d866f4aec9c44728e4c353efe0da4ac9d36c6eea502c399dc72003ba2bee2d
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: e66014c7479e7e73e16eaaa40dbe92b82825dcd5fe2b8d1480e7713fcf8e58469dfb8174471f3a31e0a0468535e5c5b49b4280986594e915fbc93ab1764ce3bd
         
     | 
| 
         Binary file 
     | 
| 
         @@ -79,7 +79,7 @@ 
     | 
|
| 
       79 
79 
     | 
    
         | 
| 
       80 
80 
     | 
    
         
             
                UniversalS3Uploader.prototype.initExternalInterface = function()
         
     | 
| 
       81 
81 
     | 
    
         
             
                {
         
     | 
| 
       82 
     | 
    
         
            -
                  var  
     | 
| 
      
 82 
     | 
    
         
            +
                  var context = this;
         
     | 
| 
       83 
83 
     | 
    
         
             
                  var flashObject = this.element.children('object.flash_uploader').get(0);
         
     | 
| 
       84 
84 
     | 
    
         | 
| 
       85 
85 
     | 
    
         
             
                  var interval = setInterval(function()
         
     | 
| 
         @@ -88,8 +88,12 @@ 
     | 
|
| 
       88 
88 
     | 
    
         
             
                    {
         
     | 
| 
       89 
89 
     | 
    
         
             
                      clearInterval(interval);
         
     | 
| 
       90 
90 
     | 
    
         | 
| 
       91 
     | 
    
         
            -
                      flashObject.sendDivId( 
     | 
| 
       92 
     | 
    
         
            -
                       
     | 
| 
      
 91 
     | 
    
         
            +
                      flashObject.sendDivId(context.element.attr('id'));
         
     | 
| 
      
 92 
     | 
    
         
            +
                      if (context.options.size)
         
     | 
| 
      
 93 
     | 
    
         
            +
                      {
         
     | 
| 
      
 94 
     | 
    
         
            +
                        flashObject.sendSize(context.options.size);
         
     | 
| 
      
 95 
     | 
    
         
            +
                      }
         
     | 
| 
      
 96 
     | 
    
         
            +
                      context.element.children('div').each(function ()
         
     | 
| 
       93 
97 
     | 
    
         
             
                      {
         
     | 
| 
       94 
98 
     | 
    
         
             
                        flashObject.sendFormData(this.className, $(this).data('value'));
         
     | 
| 
       95 
99 
     | 
    
         
             
                      });
         
     | 
| 
         @@ -108,8 +112,86 @@ 
     | 
|
| 
       108 
112 
     | 
    
         
             
                  return false;
         
     | 
| 
       109 
113 
     | 
    
         
             
                };
         
     | 
| 
       110 
114 
     | 
    
         | 
| 
      
 115 
     | 
    
         
            +
                UniversalS3Uploader.prototype.dataUrlToBlob = function(dataUrl)
         
     | 
| 
      
 116 
     | 
    
         
            +
                {
         
     | 
| 
      
 117 
     | 
    
         
            +
                  var byteString = atob(dataUrl.split(',')[1]);
         
     | 
| 
      
 118 
     | 
    
         
            +
                  var ab = new ArrayBuffer(byteString.length);
         
     | 
| 
      
 119 
     | 
    
         
            +
                  var ia = new Uint8Array(ab);
         
     | 
| 
      
 120 
     | 
    
         
            +
                  var mimeString = dataUrl.split(',')[0].split(':')[1].split(';')[0];
         
     | 
| 
      
 121 
     | 
    
         
            +
                  for (var i = 0; i < byteString.length; i++) {
         
     | 
| 
      
 122 
     | 
    
         
            +
                    ia[i] = byteString.charCodeAt(i);
         
     | 
| 
      
 123 
     | 
    
         
            +
                  }
         
     | 
| 
      
 124 
     | 
    
         
            +
                  return new Blob([ab], { type: mimeString });
         
     | 
| 
      
 125 
     | 
    
         
            +
                };
         
     | 
| 
      
 126 
     | 
    
         
            +
             
     | 
| 
      
 127 
     | 
    
         
            +
                UniversalS3Uploader.prototype.resizeAndUpload = function(file, size)
         
     | 
| 
      
 128 
     | 
    
         
            +
                {
         
     | 
| 
      
 129 
     | 
    
         
            +
                  var context = this;
         
     | 
| 
      
 130 
     | 
    
         
            +
                  var img = document.createElement("img");
         
     | 
| 
      
 131 
     | 
    
         
            +
                  img.src = window.URL.createObjectURL(file);
         
     | 
| 
      
 132 
     | 
    
         
            +
                  img.onload = function()
         
     | 
| 
      
 133 
     | 
    
         
            +
                  {
         
     | 
| 
      
 134 
     | 
    
         
            +
                    var postfix = size[0];
         
     | 
| 
      
 135 
     | 
    
         
            +
                    var width_desire = size[1];
         
     | 
| 
      
 136 
     | 
    
         
            +
                    var height_desire = size[2];
         
     | 
| 
      
 137 
     | 
    
         
            +
             
     | 
| 
      
 138 
     | 
    
         
            +
                    var width = img.width;
         
     | 
| 
      
 139 
     | 
    
         
            +
                    var height = img.height;
         
     | 
| 
      
 140 
     | 
    
         
            +
             
     | 
| 
      
 141 
     | 
    
         
            +
                    if (width_desire == -1 && height_desire == -1)
         
     | 
| 
      
 142 
     | 
    
         
            +
                    {
         
     | 
| 
      
 143 
     | 
    
         
            +
                      width_desire = width;
         
     | 
| 
      
 144 
     | 
    
         
            +
                      height_desire = height;
         
     | 
| 
      
 145 
     | 
    
         
            +
                    }
         
     | 
| 
      
 146 
     | 
    
         
            +
                    else if (width_desire == -1)
         
     | 
| 
      
 147 
     | 
    
         
            +
                    {
         
     | 
| 
      
 148 
     | 
    
         
            +
                      width_desire = width * height_desire / height;
         
     | 
| 
      
 149 
     | 
    
         
            +
                    }
         
     | 
| 
      
 150 
     | 
    
         
            +
                    else if (height_desire == -1)
         
     | 
| 
      
 151 
     | 
    
         
            +
                    {
         
     | 
| 
      
 152 
     | 
    
         
            +
                      height_desire = height * width_desire / width;
         
     | 
| 
      
 153 
     | 
    
         
            +
                    }
         
     | 
| 
      
 154 
     | 
    
         
            +
             
     | 
| 
      
 155 
     | 
    
         
            +
                    var canvas = document.createElement('canvas');
         
     | 
| 
      
 156 
     | 
    
         
            +
                    canvas.width = width_desire;
         
     | 
| 
      
 157 
     | 
    
         
            +
                    canvas.height = height_desire;
         
     | 
| 
      
 158 
     | 
    
         
            +
                    var ctx = canvas.getContext("2d");
         
     | 
| 
      
 159 
     | 
    
         
            +
                    ctx.drawImage(img, 0, 0, width_desire, height_desire);
         
     | 
| 
      
 160 
     | 
    
         
            +
                    var dataUrl = canvas.toDataURL("image/png");
         
     | 
| 
      
 161 
     | 
    
         
            +
                    var blob = context.dataUrlToBlob(dataUrl);
         
     | 
| 
      
 162 
     | 
    
         
            +
             
     | 
| 
      
 163 
     | 
    
         
            +
                    var fd = new FormData();
         
     | 
| 
      
 164 
     | 
    
         
            +
                    context.element.children('div').each(function()
         
     | 
| 
      
 165 
     | 
    
         
            +
                    {
         
     | 
| 
      
 166 
     | 
    
         
            +
                      if (this.className == 'key' && postfix)
         
     | 
| 
      
 167 
     | 
    
         
            +
                      {
         
     | 
| 
      
 168 
     | 
    
         
            +
                        var new_filename = file.name.replace(/(\.[^.]+)$/, '_' + postfix + "$1");
         
     | 
| 
      
 169 
     | 
    
         
            +
                        var key = $(this).data('value').replace(/\${filename}/, new_filename);
         
     | 
| 
      
 170 
     | 
    
         
            +
                        fd.append('key', key);
         
     | 
| 
      
 171 
     | 
    
         
            +
                      }
         
     | 
| 
      
 172 
     | 
    
         
            +
                      else
         
     | 
| 
      
 173 
     | 
    
         
            +
                      {
         
     | 
| 
      
 174 
     | 
    
         
            +
                        fd.append(this.className, $(this).data('value'));
         
     | 
| 
      
 175 
     | 
    
         
            +
                      }
         
     | 
| 
      
 176 
     | 
    
         
            +
                    });
         
     | 
| 
      
 177 
     | 
    
         
            +
                    fd.append('file', blob);
         
     | 
| 
      
 178 
     | 
    
         
            +
             
     | 
| 
      
 179 
     | 
    
         
            +
                    var xhr = new XMLHttpRequest();
         
     | 
| 
      
 180 
     | 
    
         
            +
                    xhr.open('POST', context.element.attr('action'), true);
         
     | 
| 
      
 181 
     | 
    
         
            +
                    xhr.send(fd);
         
     | 
| 
      
 182 
     | 
    
         
            +
                  };
         
     | 
| 
      
 183 
     | 
    
         
            +
                };
         
     | 
| 
      
 184 
     | 
    
         
            +
             
     | 
| 
       111 
185 
     | 
    
         
             
                UniversalS3Uploader.prototype.upload = function(file, index)
         
     | 
| 
       112 
186 
     | 
    
         
             
                {
         
     | 
| 
      
 187 
     | 
    
         
            +
                  if (this.options.size)
         
     | 
| 
      
 188 
     | 
    
         
            +
                  {
         
     | 
| 
      
 189 
     | 
    
         
            +
                    for (var i = 0; i < this.options.size.length; i++)
         
     | 
| 
      
 190 
     | 
    
         
            +
                    {
         
     | 
| 
      
 191 
     | 
    
         
            +
                      this.resizeAndUpload(file, this.options.size[i]);
         
     | 
| 
      
 192 
     | 
    
         
            +
                    }
         
     | 
| 
      
 193 
     | 
    
         
            +
                  }
         
     | 
| 
      
 194 
     | 
    
         
            +
             
     | 
| 
       113 
195 
     | 
    
         
             
                  var fd = new FormData();
         
     | 
| 
       114 
196 
     | 
    
         
             
                  this.element.children('div').each(function()
         
     | 
| 
       115 
197 
     | 
    
         
             
                  {
         
     |