Skip to content

Commit

Permalink
Fix some formatting issues and add containerKlass for css fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
joshblum committed Apr 16, 2015
2 parents 589dada + 47735cb commit 2dd1f49
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 42 deletions.
4 changes: 4 additions & 0 deletions css/ratings.css
Expand Up @@ -84,6 +84,10 @@
margin-bottom: 40px;
}

.nr-noop {
/* placeholder class */
}

.nr-label {
margin-bottom: 15px !important;
}
Expand Down
86 changes: 44 additions & 42 deletions js/ratings.js
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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 ////////////////
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand All @@ -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);
});
});
}
Expand Down Expand Up @@ -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 = $("<div>", {
"class": "nr-popup-rating-container"
});
$container.append($imdbHtml);
$container.append($tomatoHtml);
$container.append($metaHtml);
var $target = $(args.selector);

var $container = $("<div>", {
"class": args.containerKlass,
});
$container.append($imdbHtml);
$container.append($tomatoHtml);
$container.append($metaHtml);

var $target = $(args.selector);
$target[args.insertFunc]($container);
}

Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit 2dd1f49

Please sign in to comment.