Skip to content

Instantly share code, notes, and snippets.

@sta1r
Last active October 6, 2015 22:17
Show Gist options
  • Select an option

  • Save sta1r/3061021 to your computer and use it in GitHub Desktop.

Select an option

Save sta1r/3061021 to your computer and use it in GitHub Desktop.
Showtime JSON reader script
// Showtime JSON loader
if ($('#showtime-json').length){
var feedUrl = $('#showtime-json').data('url');
var limit = $('#showtime-json').data('limit');
$.getJSON( feedUrl + '&limit=' + limit + '&callback=?', function(data) {
$('.loader').hide();
var container = $('#showtime-json');
var outputNode = container.find('ul');
var count = 0;
var string = '';
if (data.data.Student) { // this is a single Showtime profile
var profileUrl = data.data.Student.Student.profileurl;
var studentName = data.data.Student.Student.firstName + ' ' + data.data.Student.Student.lastName;
var media = data.data.Student.Media;
}
if (data.data.Profiles) { // this is a group of objects in Showtime
var media = data.data.Profiles;
}
$.each(media, function(i, item) {
count++;
// define smlThumb
if (item.smlthumbcrop) {
smlThumb = item.smlthumbcrop;
} else {
// for video and publication types, use a different field
if (item.type == 'video' || item.type == 'publication') {
smlThumb = item.thumb;
} else {
smlThumb = item.thumb.split('gallery');
smlThumb = smlThumb[0] + 'smlthumb.jpg';
}
}
if (item.profileName) { //group
profileUrl = 'http://showtime.arts.ac.uk/' + item.profileName;
studentName = item.fullName;
}
// do the loop
string = '<li class="profile' + '"><div class="profile-image"><a href="' + profileUrl + '" title="View ' + studentName + ' on Showtime"><img src="' + smlThumb + '"></a></div>';
if (item.profileName) { // if this is a group, build tooltip
string += '<div class="tooltip top"><div class="arrow"></div><div class="tooltip-inner">'
+ '<div class="tooltip-thumb"><a href="' + profileUrl + '" title="View ' + item.fullName + ' on Showtime"><img src="' + item.thumb + '"></a></div>'
+ '<h4>' + item.fullName + '</h4>'
+ '<p class="course-info">' + item.course + '</p>'
+ '<p class="section-purple"><a href="' + profileUrl + '">View profile</a></p>'
+ '</div></div>';
}
string += '</li>';
outputNode.append(string);
});
$("#showtime-json .profile-image").tooltip();
});
}
@sta1r

sta1r commented Jul 6, 2012

Copy link
Copy Markdown
Author

This script gets JSON from a URL provided by a data-url argument in the HTML, and detects whether the data output is from a group of Showtime profiles or a single profile (the JSON structure is different). It then builds and displays a tooltip displayed from each thumbnail on hover. Dependencies include the JQuery Tools library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment