Skip to content

Instantly share code, notes, and snippets.

@quoid

quoid/script.js Secret

Created February 5, 2016 18:32
Show Gist options
  • Save quoid/a87499624f6581f45f93 to your computer and use it in GitHub Desktop.
Save quoid/a87499624f6581f45f93 to your computer and use it in GitHub Desktop.
code from site using amp
var trackList = []; //will hold song list json
var transEnd = 'transitionend webkitTransitionEnd'; //for tracking transition ends on screen element within credits & music section
var playerHeight = $('#player').outerHeight() + 20;
var songsLoaded = 0;
var creditsLoaded = 0;
$(window).on('resize',function() { //keeps player hidden on browser resize and start
var playerHeight = $('#player').outerHeight() + 20;
$('#player').css('transform', 'translateY(' + playerHeight + 'px)');
}).trigger('resize');
$(window).scroll(function() { //remove the bouncing animation from splash button when scrolls // re-enables it after 5sec when at top
if ($(window).scrollTop() < 1) {
setTimeout(function(){
$('.splash-more').addClass('bounce animated delayed infinite');
}, 5000);
} else {
$('.splash-more').removeClass('bounce animated delayed infinite');
}
});
$('.screen').on(transEnd, function(e) { //when credits + playlist screen fades out, make unclickable
if ($(e.target).hasClass('screen')) {
$(this).css('display', 'none');
}
});
$(document).on('click', '#credit-list .actual', function(e){ //add the class active to credit items if clicked
if (!$(e.target).hasClass('icon-close')) { //unless the icon-close element is clicked
$('#credit-list > li').removeClass('active');
$(this).addClass('active');
}
});
$(document).on('click', '#credit-list .dropdown .icon-close', function(e){ //if icon-close is clicked remove active class from element's parent li
var a = $(this).parents('li');
a.removeClass('active');
});
$(document).on('click', '#playlist .amplitude-play', function(){
var a = $('#player').outerHeight();
var b = $('#player .player-close').outerHeight();
$('body').addClass('show-player').css('padding-bottom', a + 'px');
$('.show-player #player .player-close').css('top', '-' + b + 'px');
});
$('#player .player-close').click(function(){
$('body').removeClass('show-player').css('padding-bottom', '');
$('#playlist > .item').removeClass('active');
$('#player .player-close').css('top', '');
});
function loadCredits() {
var creditList = 'assets/xml/credits.xml'; //location of xml doc
$.get( creditList, function(data) {
console.log('Attempting to load credits from ' + creditList); //logging location
var singleCredit = data.getElementsByTagName("CREDIT");
$(singleCredit).each(function(i, credit){
var creditClone = $('#credit-list .placeholder:first').clone().removeClass('placeholder').addClass('actual'); //xml takes a minute to load, so there's placeholder element that get animated out when the real data comes in
var title = credit.getElementsByTagName("TITLE")[0].childNodes;
if (title.length > 0) { //check if node (terminology might be wrong) has data, if I don't think and an XML field is missed, the code doesnt get executed
var title = credit.getElementsByTagName("TITLE")[0].childNodes[0].nodeValue; //it filed/node has data, change the variable declared above to this
creditClone.find('.item .title').text(title); //in the cloned element, add the data from this field to the element with the title class
creditClone.find('.dropdown .title .field').text(title); //same as above but for diff element
}
var role = credit.getElementsByTagName("ROLE")[0].childNodes;
if (role.length > 0) {
var role = credit.getElementsByTagName("ROLE")[0].childNodes[0].nodeValue;
creditClone.find('.item .role').text(role);
creditClone.find('.dropdown .role .field').text(role);
}
var year = credit.getElementsByTagName("YEAR")[0].childNodes;
if (year.length > 0) {
var year = credit.getElementsByTagName("YEAR")[0].childNodes[0].nodeValue;
creditClone.find('.dropdown .year .field').text(year);
}
var platform = credit.getElementsByTagName("PLATFORM")[0].childNodes;
if (platform.length > 0) {
var platform = credit.getElementsByTagName("PLATFORM")[0].childNodes[0].nodeValue;
creditClone.find('.dropdown .platform .field').text(platform);
}
var notes = credit.getElementsByTagName("NOTES")[0].childNodes;
if (notes.length > 0) {
var notes = credit.getElementsByTagName("NOTES")[0].childNodes[0].nodeValue;
creditClone.find('.dropdown .notes .field').text(notes);
}
var image = credit.getElementsByTagName("IMAGE")[0].childNodes;
if (image.length > 0) {
var image = credit.getElementsByTagName("IMAGE")[0].childNodes[0].nodeValue;
creditClone.find('.dropdown .credit-image').css('background-image', 'url(' + image + ')');
}
creditClone.appendTo("#credit-list"); //add clone to the element list
});
}, "xml" ).done(function(){
$('#credit-list').removeClass('loading').addClass('loaded'); //after all is done, remove the loading elements
}).fail(function(){
console.error("Couldn't load resource from " + creditList + "!");
$("#credit-list .screen").addClass('loading-error');
$("#credit-list .screen .loader").text('There was an issue loading the credits; please alert Pontus!!');
});
}
function loadSongs() {
var songList = 'assets/xml/songs.xml';
$.get( songList, function(data) {
console.log('Attempting to songs from ' + songList);
var singleSong = data.getElementsByTagName("SONG");
$(singleSong).each(function(i, song){
var songClone = $('#playlist .placeholder:first').clone().removeClass('placeholder').addClass('actual amplitude-play amplitude-song-container');
var songTitle = song.getElementsByTagName("TITLE")[0].childNodes;
if (songTitle.length > 0) {
var songTitle = song.getElementsByTagName("TITLE")[0].childNodes[0].nodeValue;
songClone.find('.title').text(songTitle);
}
var songDuration = song.getElementsByTagName("DURATION")[0].childNodes;
if (songDuration.length > 0) {
var songDuration = song.getElementsByTagName("DURATION")[0].childNodes[0].nodeValue;
songClone.find('.duration').text(songDuration);
}
var songLink = song.getElementsByTagName("LINK")[0].childNodes;
if (songLink.length > 0) {
var songLink = song.getElementsByTagName("LINK")[0].childNodes[0].nodeValue;
trackList.push({
name : songTitle,
artist: 'Pontus Rufelt',
url: songLink
});
songClone.attr('amplitude-song-index', i);
} else {
console.error(songTitle + ' had no link attached; disabling track!');
songClone.removeClass('amplitude-play').addClass('disabled');
}
songClone.appendTo("#playlist");
});
}, "xml" ).done(function(){
loadPlayer();
}).fail(function(){
console.error("Couldn't load resource from " + songList + "!");
$("#playlist .screen").addClass('loading-error');
$("#playlist .screen .loader").text('There was an issue loading the songs; please alert Pontus!!');
});
}
function loadPlayer() {
Amplitude.init({
"volume": 1,
"songs": trackList,
"soundcloud_client": 'f700ad55df43283e855eda8315d1adca',
"callbacks": {
"after_init": "AmplitudeLoaded",
}
});
}
function AmplitudeLoaded() {
console.log('Amplitude player successfully loaded');
$('#playlist').removeClass('loading').addClass('loaded');
}
$(document).ready( function() { //after everything is loaded run these functions
loadSongs();
loadCredits();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment