-
Notifications
You must be signed in to change notification settings - Fork 45
/
application.coffee
43 lines (35 loc) · 1.62 KB
/
application.coffee
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
$(document).ready ->
$(".playlist").addClass "closed hidden transition transition-height"
$(".cover-picker").on "click", "a", (event) ->
coverAnchor = @
coverSelected = coverAnchor.parentNode
coverActive = $(".cover-picker .active")
albumSelected = coverAnchor.href.replace "#", ""
indicatorPosition = (coverSelected.offsetLeft + (coverSelected.offsetWidth / 2) - 15)
playlistHeight = $(".playlist-inner")[0].getBoundingClientRect().height
togglePlaylistForAlbum = (album) =>
isExpanding = $(".playlist").hasClass "closed"
targetHeight = if isExpanding then 400 else 0
if isExpanding
$(".playlist").removeClass "hidden"
$(".playlist-indicator").removeClass("hidden").css "left", indicatorPosition
else
$(".playlist").on "webkitTransitionEnd", ->
$(".playlist-indicator").addClass "hidden"
$(".playlist").addClass("hidden").off "webkitTransitionEnd"
$(coverSelected).toggleClass "active"
$(".playlist").toggleClass("closed expanded").height targetHeight
switchPlaylistToAlbum = (album) ->
$(coverActive).removeClass "active"
$(coverSelected).addClass "active"
$(".playlist-indicator").css "left", indicatorPosition
if ($(coverActive).length is 0) or (coverSelected is coverActive[0])
togglePlaylistForAlbum albumSelected
else if $(coverActive).length > 0
switchPlaylistToAlbum albumSelected
coverAnchor.blur()
event.preventDefault()
canvas = document.getElementById "album-artwork"
image = new Image
image.src = coverAnchor.childNodes[0].src
ColorTunes.launch image, canvas