Skip to content
This repository has been archived by the owner on Oct 15, 2022. It is now read-only.

Commit

Permalink
Merge pull request #910 from duckduckgo/jag/movies_fmt
Browse files Browse the repository at this point in the history
movie.js:  Format the file to 4 spaces instead of tabs.
  • Loading branch information
moollaza committed Jun 27, 2014
2 parents 988ee5b + 369a617 commit 6e4016d
Showing 1 changed file with 41 additions and 48 deletions.
89 changes: 41 additions & 48 deletions share/spice/movie/movie.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
(function(env) {
"use strict";

// A change in the Rotten Tomatoes API returns images that end in _tmb.
// This changes this to _det.
function toDetail(img) {
return img.replace(/tmb\.jpg$/, "det.jpg");
}

env.ddg_spice_movie = function(api_result) {

if (!api_result) {
if(!api_result) {
return Spice.failed('movie');
}

// Get original query.
// Get original query.
var script = $('[src*="/js/spice/movie/"]')[0],
source = $(script).attr("src"),
query = source.match(/movie\/([^\/]+)/)[1];

Spice.add({
id: 'movie',
name: 'Movies',
Expand All @@ -28,70 +27,64 @@
itemType: 'Movies'
},
normalize: function(item) {
var position;
if(item.ratings.critics_rating === "Fresh" || item.ratings.critics_rating === "Certified Fresh") {
position = "-256px -144px";
} else if(item.ratings.critics_rating === "Rotten") {
position = "-272px -144px";
}

var position;

// We add these so that we can position the Rotten Tomatoes images.
if(item.ratings.critics_rating === "Fresh" || item.ratings.critics_rating === "Certified Fresh") {
position = "-256px -144px";
} else if(item.ratings.critics_rating === "Rotten") {
position = "-272px -144px";
}

// Modify the image from _tmb.jpg to _det.jpg
var image = toDetail(item.posters.detailed);
return {
rating: Math.max(item.ratings.critics_score / 20, 0),
image: image,
icon_url: DDG.get_asset_path('movie','icons-v2.png'),
icon_image: position,
icon_class: position ? 'tomato--icon' : "",
abstract: Handlebars.helpers.ellipsis(item.synopsis || item.critics_consensus, 200),
heading: item.title,
img_m: image,
url: item.links.alternate
icon_url: DDG.get_asset_path('movie', 'icons-v2.png'),
icon_image: position,
icon_class: position ? 'tomato--icon' : "",
abstract: Handlebars.helpers.ellipsis(item.synopsis || item.critics_consensus, 200),
heading: item.title,
img_m: image,
url: item.links.alternate
};
},
templates: {
group: 'media',
detail: 'products_item_detail',
group: 'media',
detail: 'products_item_detail',
options: {
variant: 'poster',
subtitle_content: Spice.movie.subtitle_content,
buy: Spice.movie.buy
subtitle_content: Spice.movie.subtitle_content,
buy: Spice.movie.buy
}
},
relevancy: {
skip_words: [
'movie',
'info',
'film',
'rt',
'rotten',
'tomatoes',
'rating',
'ratings',
'rotten'
],
primary: [
{ key: 'title' },
{ key: 'posters.detailed', match: /\.jpg$/, strict: false }
]
skip_words: ['movie', 'info', 'film', 'rt', 'rotten', 'tomatoes', 'rating', 'ratings', 'rotten'],
primary: [{
key: 'title'
}, {
key: 'posters.detailed',
match: /\.jpg$/,
strict: false
}]
}
});

// Make sure we hide the title and ratings.
// It looks nice to show only the poster of the movie.
Spice.getDOM('movie').find('.tile__body').hide();
// Make sure we hide the title and ratings.
// It looks nice to show only the poster of the movie.
Spice.getDOM('movie').find('.tile__body').hide();
};

// Convert minutes to hr. min. format.
// e.g. {{time 90}} will return 1 hr. 30 min.
Handlebars.registerHelper("time", function(runtime) {
var hours = '',
minutes = runtime;

if(runtime >= 60) {
hours = Math.floor(runtime / 60) + ' hr. ';
minutes = (runtime % 60);
}

return hours + (minutes > 0 ? minutes + ' min.' : '');
});
}(this));
}(this));

0 comments on commit 6e4016d

Please sign in to comment.