Created
August 26, 2015 21:00
-
-
Save venkatd/b9fe350b52a51d9dd5e8 to your computer and use it in GitHub Desktop.
Behavior for jumping to the right place when you click on a time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document.body).ready(function(){ | |
window.addEventListener("hashchange", forwardAudioForHash, false); | |
$("#simplecast-audio-player").bind("jPlayer_loadstart", forwardAudioForHash) | |
$("#simplecast-audio-player").bind("jPlayer_waiting", showLoading) | |
$("#simplecast-audio-player").bind("jPlayer_playing", hideLoading) | |
$("#simplecast-audio-player").bind("jPlayer_pause", hideLoading) | |
$('.player a.jp-loading').click(function(){ | |
$("#simplecast-audio-player").jPlayer("pause", seconds); | |
}); | |
}); | |
function hmsToSecondsOnly(str) { | |
var p = str.split(':'), | |
s = 0, m = 1; | |
while (p.length > 0) { | |
s += m * parseInt(p.pop(), 10); | |
m *= 60; | |
} | |
return s; | |
} | |
function forwardAudioForHash(){ | |
hash = window.location.hash | |
if (hash){ | |
timestamp = hash.replace("#", ""); | |
seconds = hmsToSecondsOnly(timestamp); | |
$("#simplecast-audio-player").jPlayer("play", seconds); | |
scrollToElementWithPadding(".podcast-header", 20); | |
} | |
} | |
function scrollToElementWithPadding(selector, padding){ | |
$('html, body').animate({ | |
scrollTop: $(selector).offset().top - padding | |
}, 1000); | |
} | |
function showLoading(){ | |
$('.player .jp-gui .jp-play').hide(); | |
$('.player .jp-gui .jp-pause').hide(); | |
$('.player .jp-gui .jp-loading').show(); | |
} | |
function hideLoading(){ | |
$('.player .jp-gui .jp-loading').hide(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Order of things to follow