summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/ui/editor/MediaUpload.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/assets/javascripts/ui/editor/MediaUpload.js')
-rw-r--r--public/assets/javascripts/ui/editor/MediaUpload.js69
1 files changed, 3 insertions, 66 deletions
diff --git a/public/assets/javascripts/ui/editor/MediaUpload.js b/public/assets/javascripts/ui/editor/MediaUpload.js
index 86bf767..6df9961 100644
--- a/public/assets/javascripts/ui/editor/MediaUpload.js
+++ b/public/assets/javascripts/ui/editor/MediaUpload.js
@@ -1,5 +1,5 @@
-var MediaUpload = View.extend({
+var MediaUpload = UploadView.extend({
el: ".fileUpload",
createAction: "/api/media/new",
@@ -7,16 +7,12 @@ var MediaUpload = View.extend({
events: {
"keydown .url": "enterSubmit",
- "change .file": "handleFileSelect",
- "submit form": "preventDefault",
},
initialize: function(opt){
+ this.__super__.initialize.call(this)
this.parent = opt.parent
- this.$csrf = this.$("[name=_csrf]")
this.$url = this.$(".url")
- this.$file = this.$(".file")
- this.$upload = this.$(".upload-icon")
},
show: function(){
@@ -45,7 +41,7 @@ var MediaUpload = View.extend({
return
}
- media._csrf = this.$csrf.val()
+ media._csrf = $("[name=_csrf]").val()
console.log(media)
var request = $.ajax({
@@ -57,67 +53,8 @@ var MediaUpload = View.extend({
}.bind(this))
},
- handleFileSelect: function(e) {
- e.stopPropagation();
- e.preventDefault();
-
- this.parent.mediaViewer.deleteArmed(false)
-
- var files = e.dataTransfer ? e.dataTransfer.files : e.target.files;
-
- for (var i = 0, f; f = files[i]; i++) {
- if ( ! f.type.match('image.*')) {
- continue;
- }
-
- this.getImageDimensions(f)
- }
- },
-
- getImageDimensions: function(f){
- var base = this
-
- this.$upload.addClass('uploading')
-
- var reader = new FileReader();
-
- 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(this.add.bind(this))
- },
-
add: function(media){
console.log(media)
- if (media.error) {
- return
- }
- this.$upload.removeClass('uploading')
this.parent.mediaViewer.add(media)
}