From 1da03906dea53336c974e81237ee97d4ea2672a6 Mon Sep 17 00:00:00 2001 From: Florent Biville Date: Tue, 19 Feb 2013 23:35:44 +0100 Subject: [PATCH] Issue #90. Change game filter dropdown to icon list. @wouatcha, you're next! --- .../WEB-INF/pages/timeline/timeline.jsp | 13 ++++---- src/main/webapp/static/css/timeline.css | 4 ++- src/main/webapp/static/js/pages/timeline.js | 31 ++++++++++++++++--- 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/src/main/webapp/WEB-INF/pages/timeline/timeline.jsp b/src/main/webapp/WEB-INF/pages/timeline/timeline.jsp index c032947..4028678 100644 --- a/src/main/webapp/WEB-INF/pages/timeline/timeline.jsp +++ b/src/main/webapp/WEB-INF/pages/timeline/timeline.jsp @@ -27,14 +27,15 @@
- - +
diff --git a/src/main/webapp/static/css/timeline.css b/src/main/webapp/static/css/timeline.css index ad83a26..87575c8 100644 --- a/src/main/webapp/static/css/timeline.css +++ b/src/main/webapp/static/css/timeline.css @@ -27,4 +27,6 @@ #arrowRight a { margin-right: 10px; background: url('../img/navNext.png') no-repeat;} #arrowLeft:hover a, #arrowRight:hover a { opacity:1;} -img.gFImg { width:70px; height:70px;} \ No newline at end of file +img.gFImg { width:70px; height:70px;} + +.gameIcon.selected { border:3px solid pink;} \ No newline at end of file diff --git a/src/main/webapp/static/js/pages/timeline.js b/src/main/webapp/static/js/pages/timeline.js index a76995d..ee1208d 100644 --- a/src/main/webapp/static/js/pages/timeline.js +++ b/src/main/webapp/static/js/pages/timeline.js @@ -7,21 +7,42 @@ define([ "use strict"; var filterId = "#gameFilter", + iconClass = ".gameIcon", hasErrors = false; return { trigger: function() { + var $icons = $(filterId + " " + iconClass); hasErrors = sanityChecker.checkIfNotExists(filterId, 'Game filter') || hasErrors; if (hasErrors) { logger.error('Script initialization failed due to multiple errors'); } else { logger.debug('Initializing game filter...'); - $(filterId).bind("change", function() { - var selectedGameIds = _.map($(filterId).val(), function(gameId) { - return parseInt(gameId, 10); - }), - allOccurrences = $("article[data-game]"); + $icons.click(function() { + var selectedGameIds, + allOccurrences = $("article[data-game]"), + newStatus = ($(this).data("selected") === undefined) ? true : !($(this).data("selected").value); + + $(this) + .toggleClass("selected", newStatus) + .data("selected", {value:newStatus}); + + + selectedGameIds = _.map( + _.filter( + $icons, + function(icon) { + var status = $(icon).data("selected"); + return !(_.isUndefined(status)) && status.value; + } + ), + function(icon) { + return $(icon).data("game-id"); + } + ); + + logger.debug(selectedGameIds); _.map(allOccurrences, function(occ) { if(_.indexOf(selectedGameIds, $(occ).data("game")) !== -1) {