diff options
Diffstat (limited to 'public/assets/javascripts/ui/editor/MediaUpload.js')
| -rw-r--r-- | public/assets/javascripts/ui/editor/MediaUpload.js | 52 |
1 files changed, 38 insertions, 14 deletions
diff --git a/public/assets/javascripts/ui/editor/MediaUpload.js b/public/assets/javascripts/ui/editor/MediaUpload.js index a66f2e8..3ade132 100644 --- a/public/assets/javascripts/ui/editor/MediaUpload.js +++ b/public/assets/javascripts/ui/editor/MediaUpload.js @@ -67,23 +67,47 @@ var MediaUpload = View.extend({ if ( ! f.type.match('image.*')) { continue; } + + this.getImageDimensions(f) + } + }, + + getImageDimensions: function(f){ + var base = this + + this.$upload.addClass('uploading') - this.$upload.addClass('uploading') - - var fd = new FormData(); - fd.append( 'image', f ) - fd.append( '_csrf', this.$csrf.val() ) + var reader = new FileReader(); - var request = $.ajax({ - url: this.uploadAction, - type: "post", - data: fd, - dataType: "json", - processData: false, - contentType: false, - }) - request.done($.proxy(this.add, this)) + reader.onload = function(e) { + var image = new Image() + image.onload = function(){ + var width = image.naturalWidth, + height = image.naturalHeight + base.upload(f, width, height) + } + image.src = e.target.result } + + reader.readAsDataURL(f); + }, + + upload: function(f, width, height){ + var fd = new FormData(); + fd.append( 'image', f ) + fd.append( 'width', width ) + fd.append( 'height', height ) + fd.append( '_csrf', this.$csrf.val() ) + + var request = $.ajax({ + url: this.uploadAction, + type: "post", + data: fd, + dataType: "json", + processData: false, + contentType: false, + }) + request.done($.proxy(this.add, this)) }, add: function(media){ |
