summaryrefslogtreecommitdiff
path: root/frontend/static/js/like.js
blob: 2d43b7b1575e48ca263455fd52497d66f61ee16c (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
89
90
91
92
93
94
95
96
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)
		{
		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.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 ()
		{
		}
	}