1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
var MediaUpload = UploadView.extend({
el: ".fileUpload",
createAction: "/api/media/new",
uploadAction: "/api/media/upload",
events: {
'mousedown': "stopPropagation",
"keydown .url": "enterSubmit",
},
initialize: function(opt){
this.__super__.initialize.call(this)
this.parent = opt.parent
this.$url = this.$(".url")
},
show: function(){
this.$el.addClass("active")
this.$url.val("")
},
hide: function(){
this.$el.removeClass("active")
},
enterSubmit: function(e){
if (e.keyCode == 13) {
e.preventDefault()
this.parse()
}
},
parse: function(){
var url = this.$url.val()
this.$url.val("")
Parser.parse(url, function(media){
if (! media) {
alert("Not a valid image/video link")
return
}
media._csrf = $("[name=_csrf]").val()
var request = $.ajax({
type: "post",
url: this.createAction,
data: media,
})
request.done(this.add.bind(this))
}.bind(this))
},
add: function(media){
console.log(media)
this.parent.mediaViewer.add(media, this.parent.mediaViewer.$myMedia)
this.parent.mediaViewer.$deleteMedia.show()
this.parent.mediaViewer.$noMedia.hide()
},
beforeUpload: function(){
this.parent.mediaViewer.deleteArmed(false)
}
})
|