jQuery( function( $ ){
var ajaxUrl = dogHaus.ajaxUrl,
siteUrl = dogHaus.siteUrl,
playlist = dogHaus.playlist,
avUrl = siteUrl + '/wp-content/av/',
audiotag = $( 'body div#doghaus-player div.player audio' ),
dataul = $( 'body div#doghaus-player div.player ul.data' ),
listol = $( 'body div#doghaus-player div.playlist ol.pl-list' ),
audioEvents = [ "abort", "canplay", "canplaythrough", "durationchange", "emptied", "ended", "error", "loadeddata", "loadedmetadata", "loadstart", "pause", "play", "playing", "progress", "ratechange", "readystatechange", "seeked", "seeking", "stalled", "suspend", "timeupdate", "volumechange", "waiting" ],
time_format = function( seconds ) {
var m = Math.floor( seconds / 60 ) < 10 ? Math.floor( seconds / 60 ) : Math.floor( seconds / 60 ),
s = Math.floor( seconds - ( m * 60 ) ) < 10 ? "0" + Math.floor( seconds - ( m * 60 ) ) : Math.floor( seconds - ( m * 60 ) )
return m + ":" + s
},
monitor = {
durationchange: function( e ) {
$( 'body div#doghaus-player div.player ul.data li.data-info div.data-voltime div#timeleft' ).text( time_format( audio.duration ) )
},
timeupdate: function( e ) {
var percentage = audio.currentTime / audio.duration * 100,
timeleft = audio.duration - audio.currentTime
$( 'body div#doghaus-player div.player ul.data li.data-info div.data-voltime div#timer' ).text( time_format( audio.currentTime ) )
$( 'body div#doghaus-player div.player ul.data li.data-info div.data-voltime div#timeleft' ).text( time_format( timeleft ) )
},
playing: function( e ) {
},
ended: function( e ) {
// go to next track in playlist. if at end, go back and play track 1
$( 'body div#doghaus-player div.player ul.controls li #play' ).removeClass( 'pause' ).attr( 'title', 'click to play' )
},
play: function( e ) {
$( 'body div#doghaus-player div.player ul.controls li a#play' ).addClass( 'pause' ).attr( 'title', 'click to pause' )
},
pause: function( e ) {
$( 'body div#doghaus-player div.player ul.controls li a#play' ).removeClass( 'pause' ).attr( 'title', 'click to play' )
}
},
track_on = 1,
//volume = $( 'body #doghaus-player div.player ul.data li.data-info div.data-voltime div#vol' ).slider({
// animate: true,
// orientation: 'horizontal',
// value: 1,
// step: 0.05,
// min: 0,
// range: 'min',
// max: 1,
// slide: function( e, ui ) {
// audio.muted = false
// audio.volume = ui.value
// }
//}),
audio = $( 'body div#doghaus-player div.player audio' ).on( monitor )[0]
function get_current_track( obj ) {
if( audiotag.children( 'source' ).length == 2 ) {
audiotag.children( 'source[type="audio/ogg"]' ).attr( 'src', obj.ogg )
audiotag.children( 'source[type="audio/mpeg"]' ).attr( 'src', obj.mp3 )
} else { audiotag.html( '
' + obj.title + '
by ' + obj.artist + '
' ) } function get_playlist_defaults() { $( 'body div#doghaus-player .playlist ol.pl-list li.track' ).each( function() { var id = $( this ).attr( 'id' ).substr( 3, 1 ) if( playlist.tracks[ id ].image != '' ) { $( this ).children( 'div.pl-list-img' ).css( 'background-image', 'url(' + playlist.tracks[ id ].image + ')' ) } }) } function get_playlist_li_status( id ) { $( 'body div#doghaus-player .playlist ol.pl-list li' ).removeClass( 'track-on' ) $( 'body div#doghaus-player .playlist ol.pl-list li#pl-' + id ).addClass( 'track-on' ) } function get_prev_next( skip ) { var new_track switch( skip ) { case 'prev': new_track = ( track_on - 1 == 0 ) ? playlist.tracks.length : track_on - 1; break; case 'next': new_track = ( track_on + 1 > playlist.tracks.length ) ? 1 : track_on + 1; break; } audio.pause() track_on = new_track get_playlist_li_status( track_on ) get_current_track( playlist.tracks[ track_on ] ) audio.play() } // remove defaults from player controls $( 'body' ).on( 'click', 'div#doghaus-player div.player ul.controls li a', function( e ) { e.preventDefault(); e.stopPropagation() }) // play-pause $( 'body div#doghaus-player div.player ul.controls li #play' ).click( function() { ( audio.ended || audio.paused ) ? audio.play() : audio.pause() }) // select prev-next track $( 'body div#doghaus-player div.player ul.controls li a.skip' ).click( function() { var skip = $( this ).attr( 'id' ) get_prev_next( skip ) }) // show-hide playlist $( 'body div#doghaus-player ul.controls li a#list' ).toggle( function() { $( this ).addClass( 'list-on' ).attr( 'title', 'hide playlist' ) $( this ).parents( '#doghaus-player' ).children( '.playlist' ).show() }, function() { $( this ).removeClass( 'list-on' ).attr( 'title', 'show playlist' ) $( this ).parents( '#doghaus-player' ).children( '.playlist' ).hide() } ) // open all external links in a new window/tab $( 'body a' ).each( function() { var lnk = new RegExp( '/' + window.location.host + '/' ) if( !lnk.test( this.href ) ) { $( this ).on( 'click', function( e ) { e.preventDefault() e.stopPropagation() window.open( this.href, '_blank' ) }) } }) // show (centered)/hide header quotation images $( 'body #branding .widget-area' ).hover( function( e ) { $( this ).children( 'aside' ).children( 'a' ).attr( 'style', function() { var w = $( this ).width(), s = Math.ceil( w / 2 ) return 'margin-right:-' + s + 'px;' }).fadeIn( 300 ) }, function( e ) { $( this ).children( 'aside' ).children( 'a' ).fadeOut( 300 ) } ) // get the title of the page a quotation credit refers to $( 'body p.single-quot a.single-quot' ).attr( 'title', function() { jQuery.ajax({ url: ajaxUrl, type: 'post', context: $( 'body p.single-quot a.single-quot' ), data: { action: 'doghaus_get_title', href: $( this ).attr( 'href' ) }, dataType: 'JSON', success: function( response ) { this.attr( 'title', response ) }/*,error: function( errorThrown ){console.log( errorThrown )}*/ }) }) get_current_track( playlist.tracks[1] ); get_playlist_defaults(); get_playlist_li_status( 1 ) })