summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/ui/editor/MediaEditor.js
blob: 47a938b7499b4a23f2ab328c457642eab3063691 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
var MediaEditor = FormView.extend({
	el: "#mediaEditor",
		
	events: {
		"click .play": "togglePlaying",
	},

	initialize: function(opt){
		this.parent = opt.parent
		this.__super__.initialize.call(this)
		
		this.$name = this.$("[name=name]")
		this.$description = this.$("[name=description]")
		this.$autoplay = this.$("[name=autoplay]")

		// image fields
		this.$widthDimension = this.$("[name=width]")
		this.$heightDimension = this.$("[name=height]")
		this.$units = this.$("[name=units]")
		
		// video fields
		this.$playButton = this.$(".play")
		this.$loop = this.$("[name=loop]")
		this.$mute = this.$("[name=mute]")
		this.$keyframe = this.$("[name=keyframe]")
	},
	
	toggle: function(state) {
    this.$el.toggleClass("active", state);
	},
	
	togglePlaying: function(){
		var state = this.scenery.toggle()
		this.$playButton.toggleClass("playing", ! state)
	},
	
	pick: function(scenery) {
		if (this.scenery) {
			this.unbind()
		}
	
		this.bind(scenery)
		this.$el.addClass("active")
		
		var media = scenery.media
		
		this.$name.val(media.title)
		this.$description.val(media.description)
		
		switch (media.type) {
			case "image":
				this.$(".image").show()
				this.$(".video").hide()
				/*
				this.$widthDimension
				this.$heightDimension
				this.$units
				*/
				
				break

			case "youtube":
			case "vimeo":
			case "video":
				this.$(".video").show()
				this.$(".image").hide()
				
				/*
				this.$loop
				this.$mute
				this.$keyframe
				*/
				
				
				break
		}
	},
	
	bind: function(scenery){
		this.scenery = scenery
	},
	
	unbind: function(){
		this.scenery = null
	},

})