summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/ui/reader
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2014-07-14 18:04:21 -0400
committerJules Laplace <jules@okfoc.us>2014-07-14 18:15:09 -0400
commit7ded9f91d3f3ab538425122be07f7436275b9b8d (patch)
tree1dd14ff86746d86b27bd6796b8843cb0e7507c66 /public/assets/javascripts/ui/reader
parent9fe187effeaf4a2e6205e2f1f52b32b8823f4f10 (diff)
play button and stuff on the viewer
Diffstat (limited to 'public/assets/javascripts/ui/reader')
-rw-r--r--public/assets/javascripts/ui/reader/MediaPlayer.js92
-rw-r--r--public/assets/javascripts/ui/reader/ReaderView.js15
2 files changed, 105 insertions, 2 deletions
diff --git a/public/assets/javascripts/ui/reader/MediaPlayer.js b/public/assets/javascripts/ui/reader/MediaPlayer.js
new file mode 100644
index 0000000..74054b4
--- /dev/null
+++ b/public/assets/javascripts/ui/reader/MediaPlayer.js
@@ -0,0 +1,92 @@
+
+var MediaPlayer = FormView.extend({
+ el: "#mediaPlayer",
+
+ events: {
+ "click .playButton": "togglePlaying",
+ "mousedown": "stopPropagation",
+ },
+
+ initialize: function(opt){
+ this.parent = opt.parent
+ this.__super__.initialize.call(this)
+
+ this.$name = this.$(".name")
+ this.$description = this.$(".description")
+
+ // image fields
+ this.$dimensions = this.$(".dimensions")
+
+ // video fields
+ this.$playButton = this.$(".playButton")
+ },
+
+ toggle: function(state) {
+ this.$el.toggleClass("active", state);
+ },
+
+ togglePlaying: function(){
+ var state = this.scenery.toggle()
+ this.$playButton.toggleClass("playing", ! state)
+ },
+
+ pick: function(scenery) {
+ var media = scenery.media
+
+ if (this.scenery) {
+ this.unbind()
+ }
+ if (media.type == "image") {
+ if ((! media.title || ! media.title.length) && (! media.description || ! media.description.length)) {
+ this.hide()
+ return
+ }
+ }
+
+ this.bind(scenery)
+ this.$el.addClass("active")
+
+ this.$name.html(media.title)
+ this.$description.html(media.description)
+
+ switch (media.type) {
+ case "image":
+ this.$(".image").show()
+ this.$(".video").hide()
+
+ this.$widthDimension.html( Number(media.widthDimension) || "" )
+ this.$heightDimension.html( Number(media.heightDimension) || "" )
+ this.$units.html( media.units || "cm" )
+
+ break
+
+ case "youtube":
+ case "vimeo":
+ case "video":
+ this.$(".video").show()
+ this.$(".image").hide()
+
+ this.$playButton.toggleClass("playing", ! this.scenery.paused())
+
+ break
+ }
+ },
+
+ hide: function(scenery){
+ if (this.scenery) {
+ this.unbind()
+ }
+ this.toggle(false)
+ },
+
+ bind: function(scenery){
+ this.scenery = scenery
+ this.scenery.mx.bound = true
+ },
+
+ unbind: function(){
+ this.scenery.mx.bound = false
+ this.scenery = null
+ },
+
+})
diff --git a/public/assets/javascripts/ui/reader/ReaderView.js b/public/assets/javascripts/ui/reader/ReaderView.js
index bbdd437..a2c2983 100644
--- a/public/assets/javascripts/ui/reader/ReaderView.js
+++ b/public/assets/javascripts/ui/reader/ReaderView.js
@@ -8,6 +8,7 @@ var ReaderView = View.extend({
},
initialize: function(){
+ this.mediaPlayer = new MediaPlayer ({ parent: this })
},
load: function(name){
@@ -27,8 +28,10 @@ var ReaderView = View.extend({
editor.permissions.clear()
- //
-
+ this.listen()
+ },
+
+ listen: function(){
var base = this
$(window).on('message', function(event){
@@ -55,6 +58,14 @@ var ReaderView = View.extend({
if (this.spinning) {
scene.camera.rotationY -= 1/180
}
+ },
+
+ pick: function(scenery){
+ this.mediaPlayer.pick(scenery)
+ },
+
+ hideExtras: function(){
+ this.mediaPlayer.hide()
}
})