');
albumDetailsContainer.attr('id', 'albumDetails' + event.data.album.albumid)
.addClass('contentContainer')
.addClass('albumContainer')
.html(
'
'
);
$('.contentContainer').hide();
$('#content').append(albumDetailsContainer);
var albumThumbnail = event.data.album.thumbnail;
var albumTitle = event.data.album.title || 'Unknown Album';
var albumArtist = event.data.album.artist.join(', ') || 'Unknown Artist';
var trackCount = data.result.limits.total;
$.each($(data.result.songs), jQuery.proxy(function (i, item) {
var trackRow, trackNumberTD;
if (i === 0) {
trackRow = $('
').addClass('fillerTrackRow2');
trackRow2.append($('').addClass('albumBG').html(' '));
for (i = 0; i < 5; i++) {
trackRow2.append($(' ').html(' '));
}
$('#albumDetails' + event.data.album.albumid + ' .resultSet').append(
trackRow2);
}
$('#albumDetails' + event.data.album.albumid + ' .albumThumb')
.append(this.generateThumb('album', albumThumbnail, albumTitle,
albumArtist))
.append($('').addClass('footerPadding'));
$('#spinner').hide();
myScroll = new iScroll('albumDetails' + event.data.album.albumid);
}
});
} else {
$('.contentContainer').hide();
$('#albumDetails' + event.data.album.albumid).show();
}
},
togglePosterView: function (event) {
var view = event.data.mode;
var wthumblist, hthumblist, hthumbdetails;
$("#toggleBanner").removeClass('activeMode');
$("#togglePoster").removeClass('activeMode');
$("#toggleLandscape").removeClass('activeMode');
switch (view) {
case 'landscape':
xbmc.core.setCookie('TVView', 'landscape');
wthumblist = '210px';
hthumblist = '118px';
hthumbdetails = '213px';
$("#toggleLandscape").addClass('activeMode');
break;
case 'banner':
xbmc.core.setCookie('TVView', 'banner');
wthumblist = '379px';
hthumblist = '70px';
hthumbdetails = '70px';
$("#toggleBanner").addClass('activeMode');
break;
default:
xbmc.core.setCookie('TVView', 'poster');
wthumblist = '135px';
hthumblist = '199px';
hthumbdetails = '559px';
$("#togglePoster").addClass('activeMode');
break;
}
$(".floatableTVShowCover, .floatableTVShowCover div.imgWrapper, .floatableTVShowCover img, " +
".floatableTVShowCover div.imgWrapper div.inner")
.css('width', wthumblist).css('height', hthumblist);
$(".floatableTVShowCoverSeason div.imgWrapper, .floatableTVShowCoverSeason div.imgWrapper div.inner," +
".floatableTVShowCoverSeason img, .floatableTVShowCoverSeason")
.css('height', hthumbdetails);
},
displayTVShowDetails: function (event) {
var tvshowDetailsContainer = $('#tvShowDetails' + event.data.tvshow.tvshowid);
$('#topScrollFade').hide();
toggle = this.toggle.detach();
if (!tvshowDetailsContainer || tvshowDetailsContainer.length === 0) {
$('#spinner').show();
xbmc.rpc.request({
'context': this,
'method': 'VideoLibrary.GetSeasons',
'params': {
'properties': [
'season',
'showtitle',
'playcount',
'episode',
'thumbnail',
'fanart'
],
'tvshowid': event.data.tvshow.tvshowid
},
'success': function (data) {
tvshowDetailsContainer = $('
');
tvshowDetailsContainer.attr('id', 'tvShowDetails' + event.data.tvshow.tvshowid)
.css('display', 'none')
.addClass('contentContainer')
.addClass('tvshowContainer');
var showThumb = this.generateThumb('tvshowseason', event.data.tvshow.thumbnail,
event.data.tvshow.title);
if (data && data.result && data.result.seasons && data.result.seasons.length >
0) {
var showDetails = $('
').addClass('showDetails');
showDetails.append(toggle);
showDetails.append($('
').html(data.result.seasons[0].showtitle).addClass(
'showTitle'));
var seasonSelectionSelect = $('').addClass('seasonPicker');
this.tvActiveShowContainer = tvshowDetailsContainer;
$.each($(data.result.seasons), function (i, item) {
var season = $('').attr('value', i);
season.text(item.label);
seasonSelectionSelect.append(season);
});
seasonSelectionSelect.bind('change', {
tvshow: event.data.tvshow.tvshowid,
seasons: data.result.seasons,
element: seasonSelectionSelect
}, jQuery.proxy(this.displaySeasonListings, this));
showDetails.append(seasonSelectionSelect);
tvshowDetailsContainer.append(showDetails);
tvshowDetailsContainer.append(showThumb);
seasonSelectionSelect.trigger('change');
$('#content').append(tvshowDetailsContainer);
if (xbmc.core.getCookie('TVView') !== null &&
xbmc.core.getCookie('TVView') !== 'banner'
) {
var view = xbmc.core.getCookie('TVView');
switch (view) {
case 'poster':
togglePoster.trigger('click');
break;
case 'landscape':
toggleLandscape.trigger('click');
break;
}
}
tvshowDetailsContainer.fadeIn();
}
$('#spinner').hide();
}
});
} else {
$('.contentContainer').hide();
$('#tvShowDetails' + event.data.tvshow.tvshowid).show();
$('#tvShowDetails' + event.data.tvshow.tvshowid + ' select').trigger('change');
}
},
displaySeasonListings: function (event) {
var selectedVal = event.data.element.val();
var seasons = event.data.seasons;
$('#topScrollFade').hide();
var oldListings = $('.episodeListingsContainer', this.tvActiveShowContainer).fadeOut();
this.tvActiveSeason = selectedVal;
xbmc.rpc.request({
'context': this,
'method': 'VideoLibrary.GetEpisodes',
'params': {
'properties': [
'title',
'thumbnail',
'episode',
'plot',
'season'
],
'season': seasons[selectedVal].season,
'tvshowid': event.data.tvshow
},
'success': function (data) {
var episodeListingsContainer = $('').addClass('episodeListingsContainer');
var episodeTable = $('
').addClass('seasonView').html(
' ' +
' '
);
$.each($(data.result.episodes), jQuery.proxy(function (i, item) {
var episodeRow = $('').addClass('episodeRow').addClass('tr' +
i % 2);
var episodePictureImg = $(' ').bind('click', {
episode: item
}, jQuery.proxy(this.playTVShow, this)).css('cursor', 'pointer');
episodePictureImg.attr('src', this.getThumbnailPath(item
.thumbnail));
var episodePicture = $('').addClass('episodeThumb').append(
episodePictureImg).bind('click', {
episode: item
}, jQuery.proxy(this.playTVShow, this));
var episodeNumber = $(' ').addClass('episodeNumber').html(item
.episode).bind('click', {
episode: item
}, jQuery.proxy(this.playTVShow, this));
var episodeTitle = $(' ').html(item.title).bind('click', {
episode: item
}, jQuery.proxy(this.playTVShow, this));
var episodeDetails = $(' ').html('').bind('click', {
episode: item
}, jQuery.proxy(this.displayEpisodeDetails, this)).css('cursor',
'pointer');
episodeRow.append(episodeNumber).append(episodeTitle).append(
episodePicture).append(episodeDetails);
episodeTable.append(episodeRow);
}, this));
episodeListingsContainer.append(episodeTable);
$(this.tvActiveShowContainer).append(episodeListingsContainer);
}
});
},
displayEpisodeDetails: function (event) {
var episodeDetails = $('').attr('id', 'episode-' + event.data.episode.episodeid).addClass(
'episodePopoverContainer');
episodeDetails.append($('
').attr('src', 'images/close-button.png').addClass('closeButton').bind(
'click', jQuery.proxy(this.hideOverlay, this)));
episodeDetails.append($('
').attr('src', this.getThumbnailPath(event.data.episode.thumbnail))
.addClass('episodeCover'));
episodeDetails.append($('
').addClass('playIcon').bind('click', {
episode: event.data.episode
}, jQuery.proxy(this.playTVShow, this)));
var episodeTitle = $('
').addClass('episodeTitle');
var yearText = event.data.episode.year ? ' (' + event.data.episode.year +
') ' : '';
episodeTitle.html(event.data.episode.title + yearText);
episodeDetails.append(episodeTitle);
if (event.data.episode.runtime) {
episodeDetails.append($('
').addClass('runtime').html('Runtime: ' + Math.ceil(
event.data.episode.runtime / 60) + ' minutes'));
}
if (event.data.episode.season) {
episodeDetails.append($('
').addClass('season').html('Season: ' + event.data
.episode.season));
}
if (event.data.episode.episode) {
episodeDetails.append($('
').addClass('episode').html('Episode: ' + event.data
.episode.episode));
}
if (event.data.episode.plot) {
episodeDetails.append($('
').addClass('plot').html('Plot: ' + event
.data.episode.plot));
}
if (event.data.episode.genre) {
episodeDetails.append($('
').addClass('genre').html('Genre: ' + event.data
.episode.genre));
}
if (event.data.episode.director) {
episodeDetails.append($('
').addClass('director').html('Directed By: ' + event
.data.episode.director));
}
this.activeCover = episodeDetails;
$('body').append(episodeDetails);
$('#overlay').show();
this.updatePlayButtonLocation();
},
playTVShow: function (event) {
xbmc.rpc.request({
'context': this,
'method': 'Player.Open',
'params': {
'item': {
'episodeid': event.data.episode.episodeid
}
},
'success': function (data) {
this.hideOverlay();
}
});
},
hideOverlay: function (event) {
if (this.activeCover) {
$(this.activeCover).remove();
this.activeCover = null;
}
$('#overlay').hide();
},
updatePlayButtonLocation: function (event) {
var movieContainer = $('.movieCover'),
playIcon;
if (movieContainer.length > 0) {
playIcon = $('.playIcon');
if (playIcon.length > 0) {
var heightpi = $(movieContainer[0]).height();
playIcon.width(Math.floor(0.65 * heightpi));
playIcon.height(heightpi);
}
}
var episodeContainer = $('.episodeCover');
if (episodeContainer.length > 0) {
playIcon = $('.playIcon');
if (playIcon.length > 0) {
var widthpi = $(episodeContainer[0]).width();
playIcon.width(widthpi);
//assume 16/9 thumb
playIcon.height(Math.floor(widthpi * 9 / 16));
}
}
},
playMovie: function (event) {
xbmc.rpc.request({
'context': this,
'method': 'Player.Open',
'params': {
'item': {
'movieid': event.data.movie.movieid
}
},
'success': function (data) {
this.hideOverlay();
}
});
},
displayMovieDetails: function (event) {
var movieDetails = $('
').attr('id', 'movie-' + event.data.movie.movieid).addClass(
'moviePopoverContainer');
movieDetails.append($('
').attr('src', 'images/close-button.png').addClass('closeButton').bind(
'click', jQuery.proxy(this.hideOverlay, this)));
movieDetails.append($('
').attr('src', this.getThumbnailPath(event.data.movie.thumbnail)).addClass(
'movieCover'));
movieDetails.append($('
').addClass('playIcon').bind('click', {
movie: event.data.movie
}, jQuery.proxy(this.playMovie, this)));
var movieTitle = $('
').addClass('movieTitle');
var yearText = event.data.movie.year ? ' (' + event.data.movie.year + ') ' :
'';
movieTitle.html(event.data.movie.title + yearText);
movieDetails.append(movieTitle);
if (event.data.movie.runtime) {
movieDetails.append($('
').addClass('runtime').html('Runtime: ' + Math.ceil(event
.data.movie.runtime / 60) + ' minutes'));
}
if (event.data.movie.plot) {
movieDetails.append($('
').addClass('plot').html(event.data.movie.plot));
}
if (event.data.movie.genre) {
movieDetails.append($('
').addClass('genre').html('Genre: ' + event.data.movie
.genre));
}
if (event.data.movie.director) {
movieDetails.append($('
').addClass('director').html('Directed By: ' + event.data
.movie.director));
}
this.activeCover = movieDetails;
$('body').append(movieDetails);
$('#overlay').show();
this.updatePlayButtonLocation();
},
playTrack: function (event) {
xbmc.rpc.request({
'context': this,
'method': 'Playlist.Clear',
'params': {
'playlistid': this.playlists["audio"]
},
'success': function (data) {
xbmc.rpc.request({
'context': this,
'method': 'Playlist.Add',
'params': {
'playlistid': this.playlists["audio"],
'item': {
'albumid': event.data.album.albumid
}
},
'success': function (data) {
xbmc.rpc.request({
'method': 'Player.Open',
'params': {
'item': {
'playlistid': this.playlists["audio"],
'position': event.data.itmnbr
}
},
'success': function () {}
});
}
});
}
});
},
loadProfile: function (event) {
return xbmc.rpc.request({
'context': this,
'method': 'Profiles.LoadProfile',
'params': {
'profile': event.data.profile.label
}
});
},
movieLibraryOpen: function () {
this.resetPage();
$('#movieLibrary').addClass('selected');
$('.contentContainer').hide();
var libraryContainer = $('#movieLibraryContainer');
if (!libraryContainer || libraryContainer.length === 0) {
$('#spinner').show();
xbmc.rpc.request({
'context': this,
'method': 'VideoLibrary.GetMovies',
'params': {
'limits': {
'start': 0
},
'properties': [
'genre',
'director',
'trailer',
'tagline',
'plot',
'plotoutline',
'title',
'originaltitle',
'lastplayed',
'runtime',
'year',
'playcount',
'rating',
'thumbnail',
'file'
],
'sort': {
'method': 'sorttitle',
'ignorearticle': true
}
},
'success': function (data) {
if (data && data.result && data.result.movies) {
libraryContainer = $('
');
libraryContainer.attr('id', 'movieLibraryContainer')
.addClass('contentContainer');
$('#content').append(libraryContainer);
} else {
libraryContainer.html('');
}
$.each($(data.result.movies), jQuery.proxy(function (i, item) {
var floatableMovieCover = this.generateThumb('movie', item
.thumbnail, item.title);
floatableMovieCover.bind('click', {
movie: item
}, jQuery.proxy(this.displayMovieDetails, this));
libraryContainer.append(floatableMovieCover);
}, this));
libraryContainer.append($('
').addClass('footerPadding'));
$('#spinner').hide();
libraryContainer.bind('scroll', {
activeLibrary: libraryContainer
}, jQuery.proxy(this.updateScrollEffects, this));
libraryContainer.trigger('scroll');
myScroll = new iScroll('movieLibraryContainer');
}
});
} else {
libraryContainer.show();
libraryContainer.trigger('scroll');
}
},
tvshowLibraryOpen: function () {
this.resetPage();
$('#tvshowLibrary').addClass('selected');
$('.contentContainer').hide();
var libraryContainer = $('#tvshowLibraryContainer');
if (!libraryContainer || libraryContainer.length === 0) {
$('#spinner').show();
toggle = $('
').addClass('toggle');
togglePoster = $('Poster ');
togglePoster.attr('id', 'togglePoster')
.css('cursor', 'pointer')
.bind('click', {
mode: 'poster'
}, jQuery.proxy(this.togglePosterView, this));
toggleBanner = $('Banner ');
toggleBanner.attr('id', 'toggleBanner')
.css('cursor', 'pointer')
.addClass('activeMode')
.bind('click', {
mode: 'banner'
}, jQuery.proxy(this.togglePosterView, this));
toggleLandscape = $('Landscape ');
toggleLandscape.attr('id', 'toggleLandscape')
.css('cursor', 'pointer')
.bind('click', {
mode: 'landscape'
}, jQuery.proxy(this.togglePosterView, this));
toggle.append(toggleBanner).append(' | ').append(togglePoster).append(' | ').append(
toggleLandscape);
this.toggle = toggle;
xbmc.rpc.request({
'context': this,
'method': 'VideoLibrary.GetTVShows',
'params': {
'properties': [
'genre',
'plot',
'title',
'lastplayed',
'episode',
'year',
'playcount',
'rating',
'thumbnail',
'studio',
'mpaa',
'premiered'
],
'sort': {
'method': 'sorttitle',
'ignorearticle': true
}
},
'success': function (data) {
if (data && data.result && data.result.tvshows) {
libraryContainer = $('
');
libraryContainer.append(toggle);
libraryContainer.attr('id', 'tvshowLibraryContainer')
.addClass('contentContainer');
$('#content').append(libraryContainer);
} else {
libraryContainer.html('');
}
$.each($(data.result.tvshows), jQuery.proxy(function (i, item) {
var floatableTVShowCover = this.generateThumb('tvshow', item
.thumbnail, item.title);
floatableTVShowCover.bind('click', {
tvshow: item
}, jQuery.proxy(this.displayTVShowDetails, this));
libraryContainer.append(floatableTVShowCover);
}, this));
libraryContainer.append($('
').addClass('footerPadding'));
$('#spinner').hide();
libraryContainer.bind('scroll', {
activeLibrary: libraryContainer
}, jQuery.proxy(this.updateScrollEffects, this));
libraryContainer.trigger('scroll');
myScroll = new iScroll('tvshowLibraryContainer');
if (xbmc.core.getCookie('TVView') !== null &&
xbmc.core.getCookie('TVView') !== 'banner'
) {
var view = xbmc.core.getCookie('TVView');
switch (view) {
case 'poster':
togglePoster.trigger('click');
break;
case 'landscape':
toggleLandscape.trigger('click');
break;
}
}
}
});
} else {
libraryContainer.prepend($(".toggle").detach()).show();
libraryContainer.trigger('scroll');
}
},
profilesOpen: function () {
this.resetPage();
$('#profiles').addClass('selected');
$('.contentContainer').hide();
var libraryContainer = $('#profilesContainer');
if (!libraryContainer || libraryContainer.length == 0) {
$('#spinner').show();
var currentProfile = "";
xbmc.rpc.request({
'method': 'Profiles.GetCurrentProfile',
'params': {
'properties': [
'lockmode'
]
},
'success': function (data) {
if (data)
if (data.result)
currentProfile = data.result.label;
}
});
xbmc.rpc.request({
'context': this,
'method': 'Profiles.GetProfiles',
'params': {
'limits': {
'start': 0
},
'properties': [
'thumbnail'
],
'sort': {
'method': 'sorttitle',
'ignorearticle': true
}
},
'success': function (data) {
if (data && data.result && data.result.profiles) {
libraryContainer = $('
');
libraryContainer.attr('id', 'profilesContainer')
.addClass('contentContainer');
$('#content').append(libraryContainer);
} else {
libraryContainer.html('');
}
$.each($(data.result.profiles), jQuery.proxy(function (i, item) {
var itemLabel = item.label;
if (currentProfile == itemLabel) {
itemLabel = itemLabel + "*";
}
var floatableProfileThumb = this.generateThumb('profile', item
.thumbnail, itemLabel);
floatableProfileThumb.bind('click', {
profile: item
}, jQuery.proxy(this.loadProfile, this));
libraryContainer.append(floatableProfileThumb);
}, this));
libraryContainer.append($('
').addClass('footerPadding'));
$('#spinner').hide();
libraryContainer.bind('scroll', {
activeLibrary: libraryContainer
}, jQuery.proxy(this.updateScrollEffects, this));
libraryContainer.trigger('scroll');
myScroll = new iScroll('profilesContainer');
}
});
} else {
libraryContainer.show();
libraryContainer.trigger('scroll');
}
},
updateScrollEffects: function (event) {
if (event.data.activeLibrary && $(event.data.activeLibrary).scrollTop() > 0) {
$('#topScrollFade').fadeIn();
} else {
$('#topScrollFade').fadeOut();
}
},
startSlideshow: function (event) {
xbmc.rpc.request({
'method': 'Player.Open',
'params': {
'item': {
'recursive': 'true',
'random': 'true',
'path': this.replaceAll(event.data.directory.file, "\\", "\\\\")
}
},
'success': function () {}
});
},
showDirectory: function (event) {
var directory = event.data.directory.file;
var jsonDirectory = this.replaceAll(directory, "\\", "\\\\");
this.resetPage();
$('#pictureLibrary').addClass('selected');
$('.contentContainer').hide();
var libraryContainer = $('#pictureLibraryDirContainer' + directory);
if (!libraryContainer || libraryContainer.length === 0) {
$('#spinner').show();
xbmc.rpc.request({
'context': this,
'method': 'Files.GetDirectory',
'params': {
'media': 'pictures',
'directory': jsonDirectory
},
'success': function (data) {
if (data && data.result && (data.result.directories || data.result.files)) {
libraryContainer = $('
');
libraryContainer.attr('id', 'pictureLibraryDirContainer' + directory)
.addClass('contentContainer');
$('#content').append(libraryContainer);
var breadcrumb = $('
');
var seperator = '/';
var item = '';
var directoryArray = directory.split(seperator);
jQuery.each(directoryArray, function (i, v) {
if (v !== '') {
item += v + seperator;
breadcrumb.append($('
').text(' > ' + v).css('float',
'left').addClass('breadcrumb'));
}
});
libraryContainer.append(breadcrumb);
libraryContainer.append($('
').css('clear', 'both'));
if (data.result.files) {
$.each($(data.result.files), jQuery.proxy(function (i, item) {
if (item.filetype == "file") {
var floatableImage = this.generateThumb('image',
item.file, item.label);
libraryContainer.append(floatableImage);
} else if (item.filetype == "directory") {
var floatableShare = this.generateThumb('directory',
item.thumbnail, item.label);
floatableShare.bind('click', {
directory: item
}, jQuery.proxy(this.showDirectory, this));
libraryContainer.append(floatableShare);
}
}, this));
}
libraryContainer.append($('
').addClass('footerPadding'));
} else {
libraryContainer.html('');
}
$('#spinner').hide();
libraryContainer.bind('scroll', {
activeLibrary: libraryContainer
}, jQuery.proxy(this.updateScrollEffects, this));
libraryContainer.trigger('scroll');
myScroll = new iScroll('#pictureLibraryDirContainer' + directory);
}
});
} else {
libraryContainer.show();
libraryContainer.trigger('scroll');
}
},
pictureLibraryOpen: function () {
this.resetPage();
$('#pictureLibrary').addClass('selected');
$('.contentContainer').hide();
var libraryContainer = $('#pictureLibraryContainer');
if (!libraryContainer || libraryContainer.length === 0) {
$('#spinner').show();
xbmc.rpc.request({
'context': this,
'method': 'Files.GetSources',
'params': {
'media': 'pictures'
},
'success': function (data) {
if (data && data.result && data.result.shares) {
libraryContainer = $('
');
libraryContainer.attr('id', 'pictureLibraryContainer')
.addClass('contentContainer');
$('#content').append(libraryContainer);
} else {
libraryContainer.html('');
}
$.each($(data.result.shares), jQuery.proxy(function (i, item) {
var floatableShare = this.generateThumb('directory', item
.thumbnail, item.label);
floatableShare.bind('click', {
directory: item
}, jQuery.proxy(this.showDirectory, this));
libraryContainer.append(floatableShare);
}, this));
libraryContainer.append($('
').addClass('footerPadding'));
$('#spinner').hide();
libraryContainer.bind('scroll', {
activeLibrary: libraryContainer
}, jQuery.proxy(this.updateScrollEffects, this));
libraryContainer.trigger('scroll');
myScroll = new iScroll('#pictureLibraryContainer');
}
});
} else {
libraryContainer.show();
libraryContainer.trigger('scroll');
}
}
};