Skip to content

Instantly share code, notes, and snippets.

@jsoningram
Last active March 22, 2016 22:09
Show Gist options
  • Save jsoningram/7db05521b9fd65acbf86 to your computer and use it in GitHub Desktop.
Save jsoningram/7db05521b9fd65acbf86 to your computer and use it in GitHub Desktop.
$(document).ready(function() {
appendTooltipHoverListener();
removeDuplicateHeaders();
wrapDates();
});
var tooltip = new $.tooltip();
function onFilterSelected(val) {
for (var ctrlName in appCtrl.coverflow) {
appCtrl.coverflow[ctrlName].getDataProvider().filter({'filter':val});
}
}
function appendTooltipHoverListener() {
var items = $('.video-thumbnail');
$.each(items, function (index, value) {
var item = $(this);
item.attr('id', 'latest-video-' + index);
$('#latest-video-' + index).unbind('mouseenter');
$('#latest-video-' + index).unbind('mouseleave');
$('#latest-video-' + index).on('mouseenter', function (ev) {
var currentTarget = $(ev.currentTarget);
setTimeout(function () {
if (currentTarget.is(':hover') && !tooltip.isDisplayedForAsset(item.data('id'))) {
var settings = {
assetId: item.data('id'),
assetType: mediaType.episode,
assetTitle: item.data('title'),
assetCategory: item.data('category'),
assetIsFree: item.data('free'),
item: currentTarget,
location: 'w'
};
tooltip.changeSettings(settings);
tooltip.show();
}
tooltip.setInUIItem(true);
}, 800);
});
$('#latest-video-' + index).on('mouseleave', function () {
tooltip.setInUIItem(false);
tooltip.remove();
});
});
}
function showParent() {
$('.accordion-contents ul').each(function() {
$(this).show();
});
}
function wrapDates() {
var dates = [];
$('.accordion-contents h4').each(function() {
dates.push($(this).attr('data-date'));
});
dates.forEach(function(date, index, dates) {
$('*[data-date="' + date + '"]').wrapAll('<div class="by-date" data-date"' + date + '" />');
});
}
function removeDuplicateHeaders() {
var seen = {};
$('.accordion-contents h4').each(function() {
var txt = $(this).text();
if (seen[txt]) {
$(this).remove();
} else {
seen[txt] = true;
}
});
}
function showHeading() {
$('.accordion-contents h4').each(function() {
$(this).show();
});
}
function displayParentDiv() {
$('.by-date').css('display',function(){
var children = $(this).children('ul');
return children.length === children.not(':visible').length ? 'none' : 'block';
});
}
$('.program-guide-menu li').each(function() {
var category = $(this).children('a').attr('data-category');
$('a.' + category).parent('li').click(function(e) {
$(this).parent('ul').children('li').each(function() {
$(this).removeClass('active-category');
});
showHeading();
$(this).addClass('active-category');
$('.by-date').show();
$('.accordion-contents ul').hide();
$('.accordion-contents ul.' + category).show();
$('.accordion-contents li.' + category).removeClass('filtered-last');
displayParentDiv();
if ('all' == category) {
$('.accordion-contents li').parent('ul').show();
$('.accordion-contents li').removeClass('filtered-last');
$('.by-date').show();
showHeading();
showParent();
e.stopImmediatePropagation();
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment