summaryrefslogtreecommitdiff
path: root/frontend/static/js/src/like.js
diff options
context:
space:
mode:
authorPepper <pepper@scannerjammer.com>2015-05-20 11:16:13 -0400
committerPepper <pepper@scannerjammer.com>2015-05-20 11:16:13 -0400
commita4916103efb2d97896c456ff0e83064b21e85d25 (patch)
treeb3eb529e4b96375109626bbeada35d4f8a2667ee /frontend/static/js/src/like.js
parent3790eedc2f48c725c586b8c7b924875fedbeb7b4 (diff)
first commit in a while
Diffstat (limited to 'frontend/static/js/src/like.js')
-rw-r--r--frontend/static/js/src/like.js97
1 files changed, 97 insertions, 0 deletions
diff --git a/frontend/static/js/src/like.js b/frontend/static/js/src/like.js
new file mode 100644
index 0000000..8ae975f
--- /dev/null
+++ b/frontend/static/js/src/like.js
@@ -0,0 +1,97 @@
+var Like =
+ {
+ timeout: false,
+ likeContentDelay: 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)
+ {
+ var domain = window.location.hostname.split('.').slice(-2).join('.')
+ d.joy("liked by "+username)
+ $("#likereport").append(
+ $("<a>").attr("href","http://"+username+"."+domain+"/").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.likeContentDelay)
+ $("#flower").fadeOut(Like.likeContentDelay)
+ $("#likereport").fadeOut(Like.likeMessageDelay, function(){$("#likereport").html("")})
+ },
+ likeContent: 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("&nbsp;&nbsp;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('&nbsp;')
+ }
+ 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.likeContentDelay)
+ 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 ()
+ {
+ }
+ }