summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/ui/editor/MediaViewer.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/assets/javascripts/ui/editor/MediaViewer.js')
-rw-r--r--public/assets/javascripts/ui/editor/MediaViewer.js193
1 files changed, 156 insertions, 37 deletions
diff --git a/public/assets/javascripts/ui/editor/MediaViewer.js b/public/assets/javascripts/ui/editor/MediaViewer.js
index 436c0cb..2ae5104 100644
--- a/public/assets/javascripts/ui/editor/MediaViewer.js
+++ b/public/assets/javascripts/ui/editor/MediaViewer.js
@@ -3,44 +3,82 @@ var MediaViewer = ModalView.extend({
el: ".mediaDrawer.mediaViewer",
destroyAction: "/api/media/destroy",
usesFileUpload: true,
-
+ loaded: false,
+ perPage: 12,
+ offset: 0,
+ fixedClose: true,
+
events: {
+ 'mousedown': "stopPropagation",
'click .foundToggle': "foundToggle",
'click .userToggle': "userToggle",
'click #deleteMedia': "deleteArmed",
+ 'click #randomize': "randomize",
'click .mediaContainer': "pick",
+ 'click .viewMore': "load",
+ 'keydown #tumblr-url': 'enterTumblrUrl',
},
initialize: function(opt){
this.__super__.initialize.call(this)
this.parent = opt.parent
+
+ this.$myMedia = this.$(".myMedia").addClass('active')
+ this.$myMediaContainer = this.$(".myMedia > .container")
+ this.$userToggle = this.$(".userToggle")
+
this.$foundMedia = this.$(".foundMedia")
- this.$myMedia = this.$(".myMedia")
+ this.$foundMediaContainer = this.$(".foundMedia > .container")
this.$foundToggle = this.$(".foundToggle")
- this.$userToggle = this.$(".userToggle")
+
+ this.$wallpaperMedia = this.$(".wallpaperMedia")
+ this.$wallpaperMediaContainer = this.$(".wallpaperMedia > .container")
+ this.$wallpaperToggle = this.$(".wallpaperToggle")
+
this.$deleteMedia = this.$("#deleteMedia")
- },
+ this.$viewMore = this.$(".viewMore")
+ this.$noMedia = this.$(".noMedia")
+ },
+ mode: "user",
+ wallpaperToggle: function(){
+ this.mode = "wallpaper"
+ this.$wallpaperMedia.addClass("active")
+ this.$foundMedia.addClass("inactive")
+ this.$myMedia.addClass("inactive").removeClass('active')
+ this.$("a").removeClass("active")
+ this.$foundToggle.addClass("active")
+ },
+
foundToggle: function(){
- this.foundMedia.addClass("active");
- this.myMedia.addClass("inactive");
- this.$("a").removeClass("active");
- this.foundToggle.addClass("active");
+ this.mode = "found"
+ this.$wallpaperMedia.removeClass("active")
+ this.$foundMedia.addClass("active")
+ this.$myMedia.addClass("inactive").removeClass('active')
+ this.$("a").removeClass("active")
+ this.$foundToggle.addClass("active")
+ this.parent.mediaUpload.hide()
+ this.parent.mediaTumblr.show()
},
userToggle: function(){
- this.foundMedia.removeClass("active");
- this.myMedia.removeClass("inactive");
- this.$("a").removeClass("active");
- this.userToggle.addClass("active");
+ this.mode = "user"
+ this.$wallpaperMedia.removeClass("active")
+ this.$foundMedia.removeClass("active")
+ this.$myMedia.removeClass("inactive").addClass('active')
+ this.$("a").removeClass("active")
+ this.$userToggle.addClass("active")
+ this.parent.mediaUpload.show()
+ this.parent.mediaTumblr.hide()
},
show: function(){
if (! this.loaded) {
this.load()
+ // this.loadTrending()
}
else {
- this.__super__.show.call(this)
+ this.reallyShow()
}
},
@@ -48,24 +86,110 @@ var MediaViewer = ModalView.extend({
this.__super__.hide.call(this)
this.deleteArmed(false)
this.parent.mediaUpload.hide()
+ this.parent.mediaTumblr.hide()
+ this.parent.cursor.message('start')
+ },
+
+ reallyShow: function(){
+ this.__super__.show.call(this)
+ if (this.mode == "user") {
+ this.userToggle()
+ }
+ else {
+ this.foundToggle()
+ }
+ this.parent.cursor.message("media")
},
load: function(){
- $.get("/api/media/user", this.populate.bind(this))
+ $.get("/api/media/user", { offset: this.offset, limit: this.perPage }, this.populate.bind(this))
+ },
+
+/*
+ loadTrending: function(){
+ var trending_imagery = [
+ 'https://d1ycxz9plii3tb.cloudfront.net/post_images/52ec0e20c9dc24f1d8000067/large.jpg',
+ 'https://d1ycxz9plii3tb.cloudfront.net/additional_images/4e6bf67bc23f490001004579/1/tall.jpg',
+ 'https://d1ycxz9plii3tb.cloudfront.net/additional_images/52dcca28139b2135030002a8/tall.jpg',
+ 'https://d1ycxz9plii3tb.cloudfront.net/additional_images/52927bb2b202a3669d000704/larger.jpg',
+ 'https://d1ycxz9plii3tb.cloudfront.net/additional_images/4f9f3a3ce262e60001000fb3/large.jpg',
+ 'http://2.bp.blogspot.com/-GD6IxUvsdOo/UdrcMFLVYNI/AAAAAAAAF2E/kbRfxMxiUlQ/s1600/okeeffe.jpg',
+ 'http://www.bobkessel.com/wordpress/wp-content/uploads/2009/10/moma-bob-kessel-410.jpg',
+ 'http://static1.artsy.net/partner_show_images/52f28f348b3b81f2fc000364/large.jpg',
+ 'http://static3.artsy.net/partner_show_images/52e83674c9dc24397f0000d8/large.jpg',
+ 'http://static0.artsy.net/partner_show_images/52d96d484b84801ef0000273/large.jpg',
+ 'http://static1.artsy.net/partner_show_images/52778616275b24f95c00011d/1/large.jpg',
+ 'http://static1.artsy.net/partner_show_images/52dc65311a1e86be6b000205/large.jpg',
+ ]
+ trending_imagery.forEach(function(url){
+ var loaded = false
+ var img = new Image ()
+ img.onload = function(){
+ if (loaded) return
+ loaded = true
+ var media = {
+ type: 'image',
+ url: url,
+ width: img.naturalWidth,
+ height: img.naturalHeight,
+ }
+ this.add(media, this.$foundMediaContainer)
+ }.bind(this)
+ img.src = url
+ if (img.complete && ! loaded) { img.onload() }
+ }.bind(this))
},
+*/
+
+ randomize: function(){
+ var $divs = this.$(".active .container").find(".mediaContainer").toArray()
+ if ($divs.length < 3) {
+ $divs = $divs.concat( this.$foundMediaContainer.find(".mediaContainer").toArray() )
+ }
+ var media_objs = $divs.map(function(el){
+ return $(el).data("media")
+ })
+ Scenery.randomize.add( media_objs )
+ this.hide()
+ },
populate: function(data){
- this.loaded = true
+ var scrollTop = this.loaded ? $('.myMedia .container').height() : 0
if (data && data.length) {
- data.forEach(this.add.bind(this))
+ if (data.length < this.perPage) {
+ this.$viewMore.hide()
+ }
+ data.forEach(function(media){
+ this.add(media, this.$myMediaContainer)
+ this.offset += 1
+ }.bind(this))
+ this.$noMedia.hide()
+ this.$deleteMedia.show()
}
else {
+ this.$viewMore.hide()
+ this.$noMedia.show()
this.$deleteMedia.hide()
}
- this.__super__.show.call(this)
+ if (this.loaded) {
+ this.$el.delay(300).animate({ scrollTop: scrollTop }, 200)
+ }
+ else {
+ this.loaded = true
+ this.reallyShow()
+ }
+ },
+
+ addUploadedMedia: function(media){
+ this.$deleteMedia.show()
+ this.$noMedia.hide()
+ this.add(media, this.$myMedia, true) // prepend
+ this.userToggle()
+ this.$el.scrollTop(0)
+ this.offset += 1
},
- add: function(media){
+ add: function(media, $container, prepend){
var image = new Image ()
var $span = $("<span>")
$span.addClass("mediaContainer")
@@ -87,13 +211,17 @@ var MediaViewer = ModalView.extend({
image.src = media.url
image.load()
break
+
+ case 'soundcloud':
+ image.src = media.thumbnail
+ break
}
$span.data("media", media)
$span.append(image)
- this.$(".myMedia").prepend($span)
- this.$deleteMedia.show()
+ if (prepend) $container.prepend($span)
+ else $container.append($span)
},
deleteIsArmed: false,
@@ -131,35 +259,23 @@ var MediaViewer = ModalView.extend({
if ($(".myMedia .mediaContainer").length == 0) {
this.$deleteMedia.hide()
+ this.$noMedia.show()
this.deleteArmed(false)
}
return
}
-// else {
-// this.picked = {}
-// this.picked.media = media
-// this.picked.image = image
-// }
-// },
-//
-// drag: function(e){
-// if (! this.pickedMedia) return
-// var media = this.picked.media
-// var image = this.picked.image
-// this.picked = null
-
this.hide()
-
+ this.parent.cursor.message('addmedia')
+
var $ants = $('.ants');
var $floatingImg = $('.floatingImg');
Scenery.nextMedia = media
-// console.log(media.type)
-
switch (media.type) {
case "video":
+ case "soundcloud":
$floatingImg.attr('src', '/assets/img/playbutton.png')
break
@@ -185,12 +301,15 @@ var MediaViewer = ModalView.extend({
$floatingImg.attr('src', '')
$(window).off('mousemove', _followCursor)
$(window).off('mousedown', _hideCursor)
+ app.off('cancel-scenery', _hideCursor)
$floatingImg.parent().removeClass('edit')
+ app.controller.cursor.message('resize')
}
$(window).on('mousemove', _followCursor)
$(window).on('mousedown', _hideCursor)
+ app.on('cancel-scenery', _hideCursor)
$ants.addClass('edit')
_followCursor(e)
},
-
+
})