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 #843 from duckduckgo/jd/guidebox_media
Browse files Browse the repository at this point in the history
guidebox: convert to media template
  • Loading branch information
Jag Talon committed Jun 19, 2014
2 parents 721c211 + fde98bb commit b89a22d
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 183 deletions.
7 changes: 6 additions & 1 deletion lib/DDG/Spice/Guidebox/Getid.pm
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ spice to => 'http://api-public.guidebox.com/v1.3/json/{{ENV{DDG_SPICE_GUIDEBOX_A

spice wrap_jsonp_callback => 1;

my %skip = map { $_ => 0 } (
'watchmen'
);

handle remainder => sub {
if ($loc->country_name eq "United States" || $loc->country_name eq "Canada"){

Expand All @@ -38,7 +42,8 @@ handle remainder => sub {
} else {
$show = $_;
}
return $show if $show;

return $show if $show && !exists $skip{lc $show};
}
return;
};
Expand Down
2 changes: 0 additions & 2 deletions lib/DDG/Spice/Guidebox/Lastshows.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ triggers any => "///***never_trigger***///";

spice to => 'http://api-public.guidebox.com/v1.3/json/{{ENV{DDG_SPICE_GUIDEBOX_APIKEY}}}/$1/watch/all/20';

spice wrap_jsonp_callback => 1;

handle remainder => sub {

# TODO
Expand Down
6 changes: 6 additions & 0 deletions share/spice/guidebox/getid/buy.handlebars
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div>
<span><a class="btn btn--primary" href="{{smart_url}}">
<span class="btn--text"> Watch Now </span>
</a></span>
{{#unless is_free_content}} <span class="paid"> Paid Content </span>{{/unless}}
</div>
55 changes: 25 additions & 30 deletions share/spice/guidebox/getid/guidebox_getid.css
Original file line number Diff line number Diff line change
@@ -1,48 +1,43 @@
.zci--guidebox li.ddgc_item img {
max-width: 100% !important;
max-height: 68px !important;
.zci__more-at__icon{
padding-bottom: 0.3em;
}

.zci--guidebox div.image_wrap {
.detail--guidebox .price{
position: relative;
top: -0.5em;
font-size: 0.9em;
color: #777777;
font-weight: normal;
}

.zci--guidebox .gb_info {
white-space: nowrap;
word-wrap: break-word;
text-overflow: ellipsis;
overflow: hidden;
margin: 0px !important
.detail--guidebox .paid{
color: #c9481c;
font-weight: bold;
}

.zci--guidebox .button {
display: inline-block;
border-radius: 3px;
padding: 3px 9px;
background: #fefefe;
border: 1px solid #bbb;
color: black;
margin-right: 10px;
.is-mobile .detail--guidebox .price{
display: none;
}

.zci--guidebox .button:hover {
border: 1px solid #80b5ff;
cursor: pointer;
text-decoration: none;
.is-mobile .detail--guidebox .btn--primary{
position: absolute;
bottom: 1.1em;
}

.zci--guidebox #ddgc_detail p {
margin-bottom: 10px;
.detail--guidebox .detail__body--pr{
border-left: 0px;
}

.zci--guidebox .grey {
color: grey;
.detail--guidebox .detail__desc{
padding-bottom: 1.3em;
}

.zci--guidebox .red {
color: #B57367
.is-mobile .detail--guidebox .paid{
position: absolute;
padding-left: 7.5em;
bottom: 1.8em;
}

.zci--guidebox .small {
font-size: 13px;
.detail--guidebox .btn--primary{
margin-right: 0.75em;
}
9 changes: 0 additions & 9 deletions share/spice/guidebox/getid/guidebox_getid.handlebars

This file was deleted.

226 changes: 100 additions & 126 deletions share/spice/guidebox/getid/guidebox_getid.js
Original file line number Diff line number Diff line change
@@ -1,141 +1,115 @@
function ddg_spice_guidebox_getid (api_result) {
"use strict";
(function(env){
"use strict";
env.ddg_spice_guidebox_getid = function(api_result) {

if (!api_result.results) {
return;
}

var SKIP_ARRAY = ["online","tv","episode","episodes","free","guidebox","watch","full"],
results = api_result.results.result,
relevant;

// Check which show is relevant to our query.
$.each(results, function(key, result) {
if (DDG.isRelevant(result.title, SKIP_ARRAY, 3) && !relevant) {
relevant = result;
if (!api_result || !api_result.results) {
return Spice.failed('guidebox');
}
});

// Exit if we didn't find anything relevant.
if (!relevant) {
return;
}

// Prevent jQuery from appending "_={timestamp}" in our url.
$.ajaxSetup({
cache: true
});
var SKIP_ARRAY = ["online","tv","episode","episodes","free","guidebox","watch","full"],
results = api_result.results.result,
relevant;

var script = $('[src*="/js/spice/guidebox/getid/"]')[0],
source = decodeURIComponent($(script).attr("src")),
matched = source.match(/\/js\/spice\/guidebox\/getid\/([a-zA-Z0-9\s]+)/),
query = matched[1];
// Check which show is relevant to our query.
$.each(results, function(key, result) {
if (DDG.isRelevant(result.title, SKIP_ARRAY, 3) && !relevant) {
relevant = result;
}
});

var metadata = {
res_title : relevant.title,
network : relevant.network,
more : relevant.url,
query : query,
};

ddg_spice_guidebox_getid.metadata = metadata;
$.getScript("/js/spice/guidebox/lastshows/series/" + relevant.id);
}

function ddg_spice_guidebox_lastshows (api_result) {
"use strict";

var metadata = ddg_spice_guidebox_getid.metadata;
// Exit if we didn't find anything relevant.
if (!relevant) {
return;
}

function toArray(obj) {
var result = [];
if($.isArray(obj)) {
return obj;
} else {
$.each(obj, function(key, value) {
result[key] = value;
});
return result;
}
// Prevent jQuery from appending "_={timestamp}" in our url.
$.ajaxSetup({
cache: true
});

var metadata = {
res_title : relevant.title,
network : relevant.network,
more : relevant.url
};

var url = '/js/spice/guidebox/lastshows/series/' + relevant.id;

$.getJSON(url, function(api_result) {

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

var isMobile = $('.is-mobile').length;

Spice.add({
id: 'guidebox',
name: 'TV',
data: toArray(api_result.results.result),
meta: {
sourceName: "Guidebox",
sourceUrl: metadata.more,
itemType: 'episodes of ' + metadata.res_title
},
templates: {
group: 'media',
options: {
variant: "video",
price: true,
buy: Spice.guidebox_getid.buy
}
},
normalize: function(item){
var subtitle_tile = "Season "+ item.season_number+ ", #" + item.episode_number;
var subtitle_detail = "(Season "+ item.season_number+ ", #" + item.episode_number+")";

var abstract_length = (isMobile ? 175 : 500);
var abstract = Handlebars.helpers.ellipsis(item.overview, abstract_length);

var aired = "Originally aired "+ Handlebars.helpers.guideBox_getDate(item.first_aired)
+ " on "+ metadata.network;

return {
image: item.thumbnail_304x171,
img: item.thumbnail_400x225,
title: item.episode_name,
ratingText: subtitle_tile,
heading: item.episode_name + subtitle_detail,
url: item.smart_url,
abstract: abstract,
price: aired
}
},
relevancy: {
primary: [
{required: 'episode_name'},
{required: 'season_number'},
{required: 'overview'}
]
}
});
});
}

Spice.add({
data : toArray(api_result.results.result),
header1 : metadata.res_title + " (TV - " + metadata.network + ")",
sourceName : "Guidebox",
sourceUrl : metadata.more,
view: "Tiles",
id : "guidebox",
templates : {
items : api_result.results.result,
item: Spice.guidebox_getid.guidebox_getid,
detail: Spice.guidebox_getid.guidebox_getid_details,
li_width : 120,
li_height : 105
function toArray(obj) {
var result = [];
if($.isArray(obj)) {
return obj;
} else {
$.each(obj, function(key, value) {
result[key] = value;
});
return result;
}
});
};

Handlebars.registerHelper("checkSeason", function(season_number, episode_number, options) {
"use strict";

if(season_number !== "0") {
return options.fn({
season_number: season_number,
episode_number: episode_number
});
}
});

Handlebars.registerHelper("getQuery", function() {
"use strict";

return ddg_spice_guidebox_getid.metadata.query;
});

Handlebars.registerHelper("getTitle", function() {
"use strict";

return ddg_spice_guidebox_getid.metadata.res_title;
});

Handlebars.registerHelper("getDate", function(first_aired) {
"use strict";
Handlebars.registerHelper("guideBox_getDate", function(first_aired) {

var aired = DDG.getDateFromString(first_aired),
var aired = DDG.getDateFromString(first_aired),
days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'],
months = [ 'January','February','March','April','May','June','July','August','September','October','November','December'];

return days[aired.getDay()] + ", " + months[aired.getMonth()] + " " + aired.getDate() + ", " + aired.getFullYear()
});

Handlebars.registerHelper("pluralize", function(string, options) {
"use strict";

if (options.hash && options.hash.singular && options.hash.plural){
var arr = string.split("|");
return arr.length > 1 ? options.hash.plural : options.hash.singular
}
return "";
});

Handlebars.registerHelper("split", function(string) {
"use strict";

return string.replace(/^\||\|$/g, "").replace(/\|/g, ", ");
});

Handlebars.registerHelper("creators", function(options) {
"use strict";

if (this.writers.length || this.directors.length){
return options.fn(this)
}
return "";
});

Handlebars.registerHelper("get_network", function(options) {
"use strict";

return ddg_spice_guidebox_getid.metadata.network;
});
return days[aired.getDay()] + ", " + months[aired.getMonth()] + " " + aired.getDate() + ", " + aired.getFullYear()
});
}(this));
15 changes: 0 additions & 15 deletions share/spice/guidebox/getid/guidebox_getid_details.handlebars

This file was deleted.

0 comments on commit b89a22d

Please sign in to comment.