summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/ui/editor/MediaTumblr.js
blob: 47419ae35c215933b12c412028740f82dc3821ec (plain)
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
var MediaTumblr = ModalView.extend({
	el: "#tumblrUpload",

	events: {
    'mousedown': "stopPropagation",
		"keydown .url": "enterSubmit",
		"click .exampleTumblr": "loadExample",
	},
	
	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){
		e.stopPropagation()
		if (e.keyCode == 13) {
			e.preventDefault()
      var url = this.$tumblrUrl.val()
			this.loadTumblr(url)
		}
	},

	loadTumblr: function(url){
		Parser.tumblr(url, function(media_list){
			console.log(media_list)
			this.parent.mediaViewer.$foundMediaContainer.empty()
			media_list.reverse().forEach(function(media){
				this.parent.mediaViewer.add(media, this.parent.mediaViewer.$foundMediaContainer)
			}.bind(this))
		}.bind(this))
	},
	
	loadExample: function(e){
	  e.preventDefault()
	  var name = $(e.currentTarget).html()
	  var url = "http://" + name + ".tumblr.com/"
	  this.$url.val(url)
	  this.loadTumblr(url)
	},

})