diff --git a/css/ratings.css b/css/ratings.css index c63e526..50d0135 100644 --- a/css/ratings.css +++ b/css/ratings.css @@ -84,6 +84,10 @@ margin-bottom: 40px; } +.nr-noop { + /* placeholder class */ +} + .nr-label { margin-bottom: 15px !important; } diff --git a/js/ratings.js b/js/ratings.js index d07083f..d1fd048 100644 --- a/js/ratings.js +++ b/js/ratings.js @@ -49,6 +49,7 @@ function makeSelectObject(selector, insertFunc, interval, klassDict) { klassDict = klassDict || {}; return merge({ + 'containerKlass': 'nr-popup-rating-container', 'selector': selector, 'insertFunc': insertFunc, 'interval': interval, @@ -244,7 +245,7 @@ function clearOld(type, args) { $target.find('.rating-link').remove(); $target.find('.nr-label').remove(); $target.find('.ratingPredictor').remove(); - $target.find('.nr-popup-rating-container').remove(); + $target.find('.' + args.containerKlass).remove(); } else if (type === 'trailer') { $target.find('.trailer-label').remove(); } @@ -359,16 +360,16 @@ function getMashapeAPIUrl() { } function getMashapePostData(title, year) { - var data = { - 'title': title - }; - - if (year !== null) { - data.year_from = year, - data.year_to = parseInt(year) + 1 - } - - return data; + var data = { + 'title': title + }; + + if (year !== null) { + data.year_from = year, + data.year_to = parseInt(year) + 1 + } + + return data; } ///////////////// USER COUNT //////////////// @@ -612,22 +613,22 @@ function getTMDBSearchType(type) { * Extracts a youtube trailer id or returns null */ function extractTrailerId(type, res) { - if (type === 'movie') { - var youtube = res.trailers.youtube; - if (youtube.length === 0) return null; - return youtube[0].source; - } else { - for (var result in res.results) { - if (result.site === "YouTube") { - return result.key; + if (type === 'movie') { + var youtube = res.trailers.youtube; + if (youtube.length === 0) return null; + return youtube[0].source; + } else { + for (var result in res.results) { + if (result.site === "YouTube") { + return result.key; + } } + return null; } - return null; } -} -/* - Search for the title, first in the CACHE and then through the API -*/ + /* + Search for the title, first in the CACHE and then through the API + */ function getRating(title, year, addArgs, callback) { var cached = checkCache(title); if (cached.inCache) { @@ -638,10 +639,10 @@ function getRating(title, year, addArgs, callback) { } addCache(title); var omdbRes = { - 'Response': 'False', + 'Response': 'False', }; var metaRes = { - 'result': false, + 'result': false, }; $.get(getIMDBAPI(title, year), function(res) { omdbRes = res; @@ -654,15 +655,15 @@ function getRating(title, year, addArgs, callback) { 'X-Mashape-Key': MASHAPE_API_KEY }, 'success': function(mashapeRes) { - for (var i = 0; i < mashapeRes.count; i++) { - if (title === mashapeRes.results[i].name) { - metaRes = mashapeRes.results[i]; - break; - } - } + for (var i = 0; i < mashapeRes.count; i++) { + if (title === mashapeRes.results[i].name) { + metaRes = mashapeRes.results[i]; + break; + } + } }, }).always(function() { - processRatingResponses(title, year, omdbRes, metaRes, callback, addArgs); + processRatingResponses(title, year, omdbRes, metaRes, callback, addArgs); }); }); } @@ -749,15 +750,15 @@ function displayRating(rating, args) { var $imdbHtml = getIMDBHtml(rating, args.imdbClass); var $tomatoHtml = getTomatoHtml(rating, args.rtClass); var $metaHtml = getMetatcriticHtml(rating, args.metacriticClass); - - var $container = $("
", { - "class": "nr-popup-rating-container" - }); - $container.append($imdbHtml); - $container.append($tomatoHtml); - $container.append($metaHtml); - - var $target = $(args.selector); + + var $container = $("
", { + "class": args.containerKlass, + }); + $container.append($imdbHtml); + $container.append($tomatoHtml); + $container.append($metaHtml); + + var $target = $(args.selector); $target[args.insertFunc]($container); } @@ -1017,6 +1018,7 @@ $(document).ready(function() { 'rating': makeSelectObject('.bluray', 'append', -1, { 'imdbClass': 'dvd-search-page', 'rtClass': 'search-rt-icon', + 'containerKlass': 'nr-noop' }), 'trailer': makeSelectObject('.synopsis', 'before', 800, { 'trailerClass': 'dvd-trailer-label',