diff options
| author | Jules Laplace <jules@okfoc.us> | 2016-11-15 13:52:28 -0500 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2016-11-15 13:52:28 -0500 |
| commit | a4ce7bf7a9e8d472b0523e74510a4ff4c394fa3f (patch) | |
| tree | 2cfeb32ec4f11793498e99e69879ad8aac17c754 /public/assets/js/lib/views/UploadView.js | |
| parent | 94ade9321a971e81c383e14186bf4c776bd304fc (diff) | |
links view
Diffstat (limited to 'public/assets/js/lib/views/UploadView.js')
| -rw-r--r-- | public/assets/js/lib/views/UploadView.js | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/public/assets/js/lib/views/UploadView.js b/public/assets/js/lib/views/UploadView.js new file mode 100644 index 0000000..89ebac4 --- /dev/null +++ b/public/assets/js/lib/views/UploadView.js @@ -0,0 +1,69 @@ +var WebcamView = View.extend({ + + el: "#photobooth", + + events: { + "change #upload-btn input": "handleFileSelect", + }, + + initialize: function(){ + this.$input = this.$('#file') + this.$snapBtn = this.$("#snap-btn") + }, + + loaded: false, + ready: function(){ + this.canvas = document.createElement("canvas") + this.ctx = this.canvas.getContext('2d') + this.$overlayer.append(this.canvas) + this.draw() + }, + + handleFileSelect: function(e) { + e.stopPropagation() + e.preventDefault() + + var files = e.dataTransfer ? e.dataTransfer.files : e.target.files + + var file = files[0] + if (! file) return + if ( ! file.type.match('image.*')) return + // this.upload(file) + var img = new Image + img.onload = function() { + var w, h + var ratio = img.naturalWidth / img.naturalHeight + if (ratio >= 4/3) { + h = 480 + w = 480 * ratio + } + else { + w = 640 + h = 640 / ratio + } + ctx.drawImage(img, 0, 0, w, h) + }.bind(this) + img.src = URL.createObjectURL(file) + }, + + upload: function(file){ + var _csrf = $("meta[name=_csrf]").attr("value") + var fd = new FormData() + fd.append('image', file) + + var request = $.ajax({ + url: "/irc/image?_csrf=" + _csrf, + type: "post", + data: fd, + dataType: "json", + processData: false, + contentType: false, + }) + request.done(this.success.bind(this)) + }, + + success: function(data){ + // probably append image.. + }, + +})
\ No newline at end of file |
