diff options
Diffstat (limited to 'www/static/js/like.js')
| -rwxr-xr-x | www/static/js/like.js | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/www/static/js/like.js b/www/static/js/like.js new file mode 100755 index 0000000..f564f4c --- /dev/null +++ b/www/static/js/like.js @@ -0,0 +1,97 @@ +var Like = + { + timeout: false, + likeVideoDelay: 1000, + likeMessageDelay: 10000, + favewords: + [ + 'dazzled', 'dangled', 'amazed', 'shocked', 'wowed', + 'spangled', 'glittered', 'blinged', 'jazzed', 'smoked', + 'rocked', 'jammed', 'stoked', 'blazed', 'pringled', 'engulfed', + ], + colors: + [ + "#ffa1b8","#ffb9a1","#ffe8a1","#ffa1e7","#a1a4ff","#cda1ff","#fca1ff","#a1d3ff","#e8a1ff","#a1f6ff","#a1ffaa","#c7ffa1" + ], + enqueue: function (username) + { + d.joy("liked by "+username) + $("#likereport").append( + $("<a>").attr("href","/profile/"+username).html(username+" was "+d.choice(Like.favewords)+"!").attr("style","color:"+d.choice(Like.colors))) + if (Viewport.focused) + Like.fire() + else + Like.pending = true + }, + fire: function () + { + d.joy("LIKE ANIMATION GO") + Like.pending = false + $("#likereport").stop(false,false).show() + d.scrollToBottom("#likereport") + $("#plant").stop(true, true).show() + $("#flower").stop(true, true).show() + if (Like.timeout) + clearTimeout(Like.timeout) + Like.timeout = setTimeout(Like.queueFade, 1000) + }, + queueFade: function timeout() + { + d.joy("LIKE ANIMATION FADE") + Like.timeout = false + $("#plant").fadeOut(Like.likeVideoDelay) + $("#flower").fadeOut(Like.likeVideoDelay) + $("#likereport").fadeOut(Like.likeMessageDelay, function(){$("#likereport").html("")}) + }, + likeVideo: function (video) + { + if (! Auth.session) + return d.error("like: not logged in") + if (video.username === Auth.username) + return d.error("like: that's you") + var data = { video: video.id, session: Auth.session, } + if (Local.isLiked(video.id)) + { + d.joy("unliking "+video.key) + if (Player.currentKey === video.key) + $("#like").removeClass("liked") + $("#like_"+video.id).removeClass("liked").html(" like") + video.liked = false + Local.unlike(video.id) + if (video.score) + { + video.score -= 1 + if (video.score < 0) + { + video.score = 0 + $("#score_"+video.id).html(' ') + } + else + { + $("#score_"+video.id).html(video.score) + } + } + $.post(API.URL.video.unlike, data) + } + else + { + d.joy("liking "+video.key) + if (Player.currentKey === video.key) + $("#like").addClass("liked") + $("#like_"+video.id).addClass("liked").html("liked") + $("#flower").show().fadeOut(Like.likeVideoDelay) + video.liked = true + Local.like(video.id) + if (video.score) + { + video.score += 1 + $("#score_"+video.id).html(video.score) + } + $.post(API.URL.video.like, data) + } + }, + init: function () + { + } + } + |
