From b4ec428228ce33a474a3a127aedb08895d801eed Mon Sep 17 00:00:00 2001 From: Ben Bleikamp Date: Mon, 23 Apr 2012 20:32:17 -0700 Subject: [PATCH 1/4] Remove .live in favor of .on .on is better because Josh Peek said so. --- app/frontend/scripts/behaviors.js.coffee | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/frontend/scripts/behaviors.js.coffee b/app/frontend/scripts/behaviors.js.coffee index 9291bb4a..946497e4 100644 --- a/app/frontend/scripts/behaviors.js.coffee +++ b/app/frontend/scripts/behaviors.js.coffee @@ -43,7 +43,7 @@ $(document).ready () -> # # data-artist - The Data attribute set on the link whose value is the # artist name for this song. - $('.artist').live 'click', () -> + $(document).on 'click', '.artist', () -> element = $(@) artist = escape(element.data('artist')) updateSongs("/artist/"+artist, "GET") @@ -53,7 +53,7 @@ $(document).ready () -> # # data-artist - The Data attribute set on the link whose value is the # artist name for this song. - $('.album').live 'click', () -> + $(document).on 'click', '.album', () -> element = $(@) artist = escape(element.data('artist')) album = escape(element.data('album')) @@ -114,11 +114,14 @@ $(document).ready () -> play.spin(false) false + # Determines whether this song should be added or removed from the queue + # + # Queues up this song. # # data-song-id - The Data attribute set on the link whose value is the # persistent ID of the song. - $('.add-to-queue').live 'click', () -> + $(document).on 'click', '.add-to-queue', () -> element = $(@) id = element.data('song-id') $.ajax @@ -127,14 +130,14 @@ $(document).ready () -> data: id: id success: (response) -> - alert 'added!' + false # Removes this song from the queue. # # data-song-id - The Data attribute set on the link whose value is the # persistent ID of the song. - $('.remove-from-queue').live 'click', () -> + $(document).on 'click', '.remove-from-queue', () -> element = $(@) id = element.data('song-id') $.ajax @@ -143,5 +146,5 @@ $(document).ready () -> data: id: id success: (response) -> - alert 'removed!' + false \ No newline at end of file From 6aacbc9ef0f1882cb0cb209fe8dc6a10bb534d61 Mon Sep 17 00:00:00 2001 From: Ben Bleikamp Date: Mon, 23 Apr 2012 20:59:01 -0700 Subject: [PATCH 2/4] Kill alerts on queue and unqueue Follows the same pattern used for replacing the Star with selected or unselected state depending on click. --- app/frontend/scripts/behaviors.js.coffee | 8 ++++++-- app/frontend/scripts/helpers.js.coffee | 9 +++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/frontend/scripts/behaviors.js.coffee b/app/frontend/scripts/behaviors.js.coffee index 946497e4..356625fa 100644 --- a/app/frontend/scripts/behaviors.js.coffee +++ b/app/frontend/scripts/behaviors.js.coffee @@ -122,6 +122,7 @@ $(document).ready () -> # data-song-id - The Data attribute set on the link whose value is the # persistent ID of the song. $(document).on 'click', '.add-to-queue', () -> + play.spin(true) element = $(@) id = element.data('song-id') $.ajax @@ -130,7 +131,8 @@ $(document).ready () -> data: id: id success: (response) -> - + element.replaceWith(queue(id, true)) + play.spin(false) false # Removes this song from the queue. @@ -138,6 +140,7 @@ $(document).ready () -> # data-song-id - The Data attribute set on the link whose value is the # persistent ID of the song. $(document).on 'click', '.remove-from-queue', () -> + play.spin(true) element = $(@) id = element.data('song-id') $.ajax @@ -146,5 +149,6 @@ $(document).ready () -> data: id: id success: (response) -> - + element.replaceWith(queue(id, false)) + play.spin(false) false \ No newline at end of file diff --git a/app/frontend/scripts/helpers.js.coffee b/app/frontend/scripts/helpers.js.coffee index b4fabf3e..a0867d65 100644 --- a/app/frontend/scripts/helpers.js.coffee +++ b/app/frontend/scripts/helpers.js.coffee @@ -62,6 +62,15 @@ play.renderStar = (id, starred) -> }) Mustache.to_html(templates.star,song,templates) +# Queue or unqueue a song +# +play.queue = (id, queued) -> + song = new Song({ + id: id + queued: queued + }) + Mustache.to_html(templates.queuing,song,templates) + # Takes a JSON response and parses it for our common Song attributes. # # json - The common JSON endpoint we return. From 61c0252f308f2ef3f751da2f8f45224124a5ebbc Mon Sep 17 00:00:00 2001 From: Ben Bleikamp Date: Mon, 23 Apr 2012 21:11:08 -0700 Subject: [PATCH 3/4] If it's not documented it doesn't exist. --- app/frontend/scripts/helpers.js.coffee | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/frontend/scripts/helpers.js.coffee b/app/frontend/scripts/helpers.js.coffee index a0867d65..e9c199e4 100644 --- a/app/frontend/scripts/helpers.js.coffee +++ b/app/frontend/scripts/helpers.js.coffee @@ -64,6 +64,10 @@ play.renderStar = (id, starred) -> # Queue or unqueue a song # +# id - The ID of the song +# queued - The Boolean value of whether this song should be queued or not. +# 'true' means Add to Queue, 'false' means Remove from Queue +# play.queue = (id, queued) -> song = new Song({ id: id From 14c286e57aefd6facd1be2404731472110431912 Mon Sep 17 00:00:00 2001 From: Ben Bleikamp Date: Mon, 23 Apr 2012 22:43:52 -0700 Subject: [PATCH 4/4] Remove stray comment --- app/frontend/scripts/behaviors.js.coffee | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/frontend/scripts/behaviors.js.coffee b/app/frontend/scripts/behaviors.js.coffee index 356625fa..16bffbb6 100644 --- a/app/frontend/scripts/behaviors.js.coffee +++ b/app/frontend/scripts/behaviors.js.coffee @@ -114,9 +114,6 @@ $(document).ready () -> play.spin(false) false - # Determines whether this song should be added or removed from the queue - # - # Queues up this song. # # data-song-id - The Data attribute set on the link whose value is the