Skip to content

Instantly share code, notes, and snippets.

@sta1r
Last active December 28, 2015 05:19
Show Gist options
  • Select an option

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

Select an option

Save sta1r/7449430 to your computer and use it in GitHub Desktop.
// Showtime JSON loader
if ($('.showtime-json').length){
// with a lightbox use-case, Magnific is a dependency. The .lightbox call further down shouldn't fire, since the Showtime lightbox only functions inside the getJSON.
jQuery.getScript('http://d27lwoqz7s24cy.cloudfront.net/assets/js/magnific-lightbox.js', function() {
var outputNode = $('.showtime-json');
jQuery.each(outputNode, function(i) {
var _node = '';
_node = $(this);
var feedUrl = _node.data('url');
// set a feed limit (this only works for Profiles, for Student we have to set the limit via a counter)
var limit = _node.data('limit');
jQuery.getJSON( feedUrl + '&limit=' + limit + '&callback=?', function(data) {
var string = '';
var media = '';
var studentName = '';
var profileUrl = '';
var counter = 0;
if (data.data.Student) { // this is a single Showtime profile
profileUrl = data.data.Student.Student.profileurl;
studentName = data.data.Student.Student.firstName + ' ' + data.data.Student.Student.lastName;
media = data.data.Student.Media;
}
if (data.data.Profiles) { // this is a group of objects in Showtime
media = data.data.Profiles;
}
jQuery.each(media, function(i, item) {
if (counter < limit) {
if (item.type == 'video' || item.type == 'publication') {
item.profileImg = item.thumb;
item.zoomImg = item.thumb;
} else {
profileImg = item.thumb.split('gallery');
item.profileImg = profileImg[0] + 'profile.jpg';
item.zoomImg = profileImg[0] + 'screen.jpg';
}
if (item.profileName) { //group
profileUrl = 'http://showtime.arts.ac.uk/' + item.profileName;
studentName = item.fullName;
}
string = '<li><a class="zoom no-border" href= "' + item.zoomImg + '" title="' + studentName + '" data-profile-url="' + profileUrl + '" style="background-image: url('+item.profileImg+')"></a></li>';
_node.append(string);
counter++;
} else {
return false;
}
}); // end each loop
$('.zoom').magnificPopup({
type: 'image',
image: {
titleSrc: function(item) {
return item.el.attr('title') + ' - <a class="no-border" href="' + item.el.data('profile-url') + '">View profile</a>';
}
},
gallery: {
enabled: true,
navigateByImgClick: true,
preload: [0,1] // Will preload 0 - before current, and 1 after the current image
}
});
}); // end getJSON loop
}); // end each loop
}); // end getScript loop
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment