From cf5c3a783a25a5a094be82b41cd66988c073df80 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 28 Apr 2013 11:36:48 -0400 Subject: Reorganise JS and get characters from lasest video * Reorganise frontend JavaScript to make it more compartmentalised * Grab characters from the latest video --- public/javascripts/app.js | 57 +++++++++++++++++++++++++++++++++++ public/javascripts/main.js | 42 ++------------------------ public/javascripts/parse-interface.js | 37 +++++++++++++++++++++++ routes/character-images.js | 3 +- views/index.ejs | 3 ++ 5 files changed, 101 insertions(+), 41 deletions(-) create mode 100644 public/javascripts/app.js create mode 100644 public/javascripts/parse-interface.js diff --git a/public/javascripts/app.js b/public/javascripts/app.js new file mode 100644 index 0000000..c54651a --- /dev/null +++ b/public/javascripts/app.js @@ -0,0 +1,57 @@ +var App = App || null; + +(function() { + var cApp = function() { + this.characters = null; + this.answer = null; + + + // CoverFlow + var initialise_js_cover_flow = function(playlist) { + coverflow('character-select-container').setup({ + width: '100%', + playlist: playlist, + coverheight: 130, + textoffset: 68 + }).on('ready', function() { + this.on('click', function() { + alert('chosen'); + }); + }); + }; + + this.initialize_video = function(url) { + + }; + + this.get_characters = function(series_id) { + // Populate characters + var that = this; + var $character_container = $('#character-select .flow'); + $.get( + '/character-images/' + series_id, + function(response) { + var r = JSON.parse(response); + + $character_container.empty() + + var playlist = [] + for (var i = 0; i < r.characters.length; i++) { + playlist.push({ + image: r.characters[i].image, + title: r.characters[i].name + }); + } + initialise_js_cover_flow(playlist); + + that.characters = _.pluck(r.characters, 'tms_personId'); + } + ); + }; + + + return this; + }; + + App = new cApp(); +})(); \ No newline at end of file diff --git a/public/javascripts/main.js b/public/javascripts/main.js index b76912e..0c1ba4e 100644 --- a/public/javascripts/main.js +++ b/public/javascripts/main.js @@ -1,41 +1,3 @@ -// CoverFlow (function() { - var initialise_js_cover_flow = function(playlist) { - coverflow('character-select-container').setup({ - width: '100%', - playlist: playlist, - coverheight: 130, - textoffset: 68 - }).on('ready', function() { - this.on('click', function() { - alert('chosen'); - }); - }); - }; - - // Populate characters - - // Change template settings to use {{}} delimiters - _.templateSettings = { - interpolate: /\{\{(.+?)\}\}/g - }; - - var $character_container = $('#character-select .flow'); - $.get( - '/character-images/8680539', - function(response) { - var r = JSON.parse(response); - - $character_container.empty() - - var playlist = [] - for (var i = 0; i < r.characters.length; i++) { - playlist.push({ - image: r.characters[i].image, - title: r.characters[i].name - }); - } - initialise_js_cover_flow(playlist); - } - ); -})(); \ No newline at end of file + ParseInterface.get_last_charade(); +})(); diff --git a/public/javascripts/parse-interface.js b/public/javascripts/parse-interface.js new file mode 100644 index 0000000..e58b243 --- /dev/null +++ b/public/javascripts/parse-interface.js @@ -0,0 +1,37 @@ +var ParseInterface = ParseInterface || null; + +(function() { + var cParseInterface = function() { + var application_id = '6jaGjImHFtbJLkAWJRnnLTHfD01nmWHAIrAKNYge'; + var javascript_key = 'zA6og358R2Wg5NVAHWj81zeFz2WQZ5u2AhHFPCjN'; + Parse.initialize(application_id, javascript_key); + + var ContestObject = Parse.Object.extend('ContestObject'); + + this.get_last_charade = function() { + var that = this; + var query = new Parse.Query(ContestObject); + query.limit(1); + query.descending('createdAt'); + query.find({ + success: function(response) { + that._process_charade(response[0]); + } + }); + }; + + this._process_charade = function(contest_instance) { + var video_url = contest_instance.get('video_url'); + var series_id = contest_instance.get('series_id'); + + App.answer = contest_instance.get('personId'); + App.initialize_video(video_url); + App.get_characters(series_id); + }; + + + return this; + }; + + ParseInterface = new cParseInterface(); +})(); \ No newline at end of file diff --git a/routes/character-images.js b/routes/character-images.js index f4ef9b6..a30ee9c 100644 --- a/routes/character-images.js +++ b/routes/character-images.js @@ -42,7 +42,8 @@ module.exports = function(req, res) { that.data.character_images.characters.push({ image: 'http://developer.tmsimg.com/' + r.preferredImage.uri + '?api_key=' + config.tms.key + '&h=100', - name: r.preferredImage.caption.content + name: r.preferredImage.caption.content, + tms_personId: r.personId }); callback(); diff --git a/views/index.ejs b/views/index.ejs index 31d31f3..4b800e5 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -16,6 +16,7 @@ +
@@ -43,6 +44,8 @@ + +