add requirejs

This commit is contained in:
Luke Pulverenti 2015-05-08 23:48:43 -04:00
parent 03ca18cf4f
commit 4e71751d0f
20 changed files with 379 additions and 520 deletions

View file

@ -30,10 +30,6 @@
var messageNamespace = 'urn:x-cast:com.google.cast.mediabrowser.v3';
var cPlayer = {
deviceState: DEVICE_STATE.IDLE
};
var CastPlayer = function () {
/* device variables */
@ -531,7 +527,7 @@
};
// Create Cast Player
var castPlayer = new CastPlayer();
var castPlayer;
function chromecastPlayer() {
@ -843,15 +839,27 @@
};
}
MediaController.registerPlayer(new chromecastPlayer());
function initializeChromecast() {
$(MediaController).on('playerchange', function () {
castPlayer = new CastPlayer();
if (MediaController.getPlayerInfo().name == PlayerName) {
if (castPlayer.deviceState != DEVICE_STATE.ACTIVE && castPlayer.isInitialized) {
castPlayer.launchApp();
MediaController.registerPlayer(new chromecastPlayer());
$(MediaController).on('playerchange', function () {
if (MediaController.getPlayerInfo().name == PlayerName) {
if (castPlayer.deviceState != DEVICE_STATE.ACTIVE && castPlayer.isInitialized) {
castPlayer.launchApp();
}
}
}
});
});
}
if ($.browser.chrome) {
requirejs(["thirdparty/cast_sender"], function () {
initializeChromecast();
});
}
})(window, window.chrome, console);

View file

@ -1292,25 +1292,28 @@ $(document).on('pagebeforeshow', "#dashboardPage", DashboardPage.onPageShow)
function takeTour(page, userId) {
$.swipebox([
{ href: 'css/images/tour/dashboard/dashboard.png', title: Globalize.translate('DashboardTourDashboard') },
{ href: 'css/images/tour/dashboard/help.png', title: Globalize.translate('DashboardTourHelp') },
{ href: 'css/images/tour/dashboard/users.png', title: Globalize.translate('DashboardTourUsers') },
{ href: 'css/images/tour/dashboard/sync.png', title: Globalize.translate('DashboardTourSync') },
{ href: 'css/images/tour/dashboard/cinemamode.png', title: Globalize.translate('DashboardTourCinemaMode') },
{ href: 'css/images/tour/dashboard/chapters.png', title: Globalize.translate('DashboardTourChapters') },
{ href: 'css/images/tour/dashboard/subtitles.png', title: Globalize.translate('DashboardTourSubtitles') },
{ href: 'css/images/tour/dashboard/plugins.png', title: Globalize.translate('DashboardTourPlugins') },
{ href: 'css/images/tour/dashboard/notifications.png', title: Globalize.translate('DashboardTourNotifications') },
{ href: 'css/images/tour/dashboard/scheduledtasks.png', title: Globalize.translate('DashboardTourScheduledTasks') },
{ href: 'css/images/tour/dashboard/mobile.png', title: Globalize.translate('DashboardTourMobile') },
{ href: 'css/images/tour/enjoy.jpg', title: Globalize.translate('MessageEnjoyYourStay') }
], {
afterClose: function () {
dismissWelcome(page, userId);
$('.welcomeMessage', page).hide();
},
hideBarsDelay: 30000
Dashboard.loadSwipebox().done(function () {
$.swipebox([
{ href: 'css/images/tour/dashboard/dashboard.png', title: Globalize.translate('DashboardTourDashboard') },
{ href: 'css/images/tour/dashboard/help.png', title: Globalize.translate('DashboardTourHelp') },
{ href: 'css/images/tour/dashboard/users.png', title: Globalize.translate('DashboardTourUsers') },
{ href: 'css/images/tour/dashboard/sync.png', title: Globalize.translate('DashboardTourSync') },
{ href: 'css/images/tour/dashboard/cinemamode.png', title: Globalize.translate('DashboardTourCinemaMode') },
{ href: 'css/images/tour/dashboard/chapters.png', title: Globalize.translate('DashboardTourChapters') },
{ href: 'css/images/tour/dashboard/subtitles.png', title: Globalize.translate('DashboardTourSubtitles') },
{ href: 'css/images/tour/dashboard/plugins.png', title: Globalize.translate('DashboardTourPlugins') },
{ href: 'css/images/tour/dashboard/notifications.png', title: Globalize.translate('DashboardTourNotifications') },
{ href: 'css/images/tour/dashboard/scheduledtasks.png', title: Globalize.translate('DashboardTourScheduledTasks') },
{ href: 'css/images/tour/dashboard/mobile.png', title: Globalize.translate('DashboardTourMobile') },
{ href: 'css/images/tour/enjoy.jpg', title: Globalize.translate('MessageEnjoyYourStay') }
], {
afterClose: function () {
dismissWelcome(page, userId);
$('.welcomeMessage', page).hide();
},
hideBarsDelay: 30000
});
});
}

View file

@ -264,6 +264,13 @@
function initializeTree(page, currentUser, openItems, selectedId) {
MetadataEditor.loadJsTree().done(function () {
initializeTreeInternal(page, currentUser, openItems, selectedId);
});
}
function initializeTreeInternal(page, currentUser, openItems, selectedId) {
nodesToLoad = [];
selectedNodeId = null;
@ -355,8 +362,8 @@
if (selectedNodeId && node.children && node.children.indexOf(selectedNodeId) != -1) {
setTimeout(function() {
setTimeout(function () {
scrollToNode($.mobile.activePage, selectedNodeId);
}, 500);
}
@ -473,8 +480,22 @@
return query;
};
self.loadJsTree = function () {
var deferred = DeferredBuilder.Deferred();
require([
'thirdparty/jstree3.0.8/jstree.min',
'css!thirdparty/jstree3.0.8/themes/default/style.min'
], function () {
deferred.resolve();
});
return deferred.promise();
};
ensureInitialValues();
}
})(jQuery, document, window);

View file

@ -572,30 +572,33 @@
function takeTour(page, userId) {
$.swipebox([
{ href: 'css/images/tour/web/tourcontent.jpg', title: Globalize.translate('WebClientTourContent') },
{ href: 'css/images/tour/web/tourmovies.jpg', title: Globalize.translate('WebClientTourMovies') },
{ href: 'css/images/tour/web/tourmouseover.jpg', title: Globalize.translate('WebClientTourMouseOver') },
{ href: 'css/images/tour/web/tourtaphold.jpg', title: Globalize.translate('WebClientTourTapHold') },
{ href: 'css/images/tour/web/tourmysync.png', title: Globalize.translate('WebClientTourMySync') },
{ href: 'css/images/tour/web/toureditor.png', title: Globalize.translate('WebClientTourMetadataManager') },
{ href: 'css/images/tour/web/tourplaylist.png', title: Globalize.translate('WebClientTourPlaylists') },
{ href: 'css/images/tour/web/tourcollections.jpg', title: Globalize.translate('WebClientTourCollections') },
{ href: 'css/images/tour/web/tourusersettings1.png', title: Globalize.translate('WebClientTourUserPreferences1') },
{ href: 'css/images/tour/web/tourusersettings2.png', title: Globalize.translate('WebClientTourUserPreferences2') },
{ href: 'css/images/tour/web/tourusersettings3.png', title: Globalize.translate('WebClientTourUserPreferences3') },
{ href: 'css/images/tour/web/tourusersettings4.png', title: Globalize.translate('WebClientTourUserPreferences4') },
{ href: 'css/images/tour/web/tourmobile1.jpg', title: Globalize.translate('WebClientTourMobile1') },
{ href: 'css/images/tour/web/tourmobile2.png', title: Globalize.translate('WebClientTourMobile2') },
{ href: 'css/images/tour/enjoy.jpg', title: Globalize.translate('MessageEnjoyYourStay') }
], {
afterClose: function () {
dismissWelcome(page, userId);
$('.welcomeMessage', page).hide();
Dashboard.loadSwipebox().done(function () {
loadConfigureViewsWelcomeMessage(page, userId);
},
hideBarsDelay: 30000
$.swipebox([
{ href: 'css/images/tour/web/tourcontent.jpg', title: Globalize.translate('WebClientTourContent') },
{ href: 'css/images/tour/web/tourmovies.jpg', title: Globalize.translate('WebClientTourMovies') },
{ href: 'css/images/tour/web/tourmouseover.jpg', title: Globalize.translate('WebClientTourMouseOver') },
{ href: 'css/images/tour/web/tourtaphold.jpg', title: Globalize.translate('WebClientTourTapHold') },
{ href: 'css/images/tour/web/tourmysync.png', title: Globalize.translate('WebClientTourMySync') },
{ href: 'css/images/tour/web/toureditor.png', title: Globalize.translate('WebClientTourMetadataManager') },
{ href: 'css/images/tour/web/tourplaylist.png', title: Globalize.translate('WebClientTourPlaylists') },
{ href: 'css/images/tour/web/tourcollections.jpg', title: Globalize.translate('WebClientTourCollections') },
{ href: 'css/images/tour/web/tourusersettings1.png', title: Globalize.translate('WebClientTourUserPreferences1') },
{ href: 'css/images/tour/web/tourusersettings2.png', title: Globalize.translate('WebClientTourUserPreferences2') },
{ href: 'css/images/tour/web/tourusersettings3.png', title: Globalize.translate('WebClientTourUserPreferences3') },
{ href: 'css/images/tour/web/tourusersettings4.png', title: Globalize.translate('WebClientTourUserPreferences4') },
{ href: 'css/images/tour/web/tourmobile1.jpg', title: Globalize.translate('WebClientTourMobile1') },
{ href: 'css/images/tour/web/tourmobile2.png', title: Globalize.translate('WebClientTourMobile2') },
{ href: 'css/images/tour/enjoy.jpg', title: Globalize.translate('MessageEnjoyYourStay') }
], {
afterClose: function () {
dismissWelcome(page, userId);
$('.welcomeMessage', page).hide();
loadConfigureViewsWelcomeMessage(page, userId);
},
hideBarsDelay: 30000
});
});
}

View file

@ -196,9 +196,12 @@
index = Math.max(index || 0, 0);
$.swipebox(slideshowItems, {
initialIndexOnArray: index,
hideBarsDelay: 30000
Dashboard.loadSwipebox().done(function () {
$.swipebox(slideshowItems, {
initialIndexOnArray: index,
hideBarsDelay: 30000
});
});
}

View file

@ -545,13 +545,18 @@
if (AppInfo.enableBottomTabs) {
$('.libraryViewNav', page).addClass('bottomLibraryViewNav');
$(page).addClass('noSecondaryNavPage');
$(function() {
$('.footer').addClass('footerOverBottomTabs');
});
} else {
$('.libraryViewNav', page).each(function () {
initHeadRoom(this);
});
}
}).on('pageshow', ".libraryPage", function () {
@ -574,10 +579,13 @@
return;
}
// construct an instance of Headroom, passing the element
var headroom = new Headroom(elem);
// initialise
headroom.init();
requirejs(["thirdparty/headroom"], function () {
// construct an instance of Headroom, passing the element
var headroom = new Headroom(elem);
// initialise
headroom.init();
});
}
function initializeApiClient(apiClient) {

View file

@ -420,13 +420,16 @@
}
if (AppInfo.enableHeadRoom) {
$('.tvGuideHeader', page).each(function () {
requirejs(["thirdparty/headroom"], function () {
// construct an instance of Headroom, passing the element
var headroom = new Headroom(this);
// initialise
headroom.init();
$('.tvGuideHeader', page).each(function () {
// construct an instance of Headroom, passing the element
var headroom = new Headroom(this);
// initialise
headroom.init();
});
});
}

View file

@ -137,6 +137,10 @@
};
self.getPlayers = function() {
return players;
};
self.getTargets = function () {
var deferred = $.Deferred();
@ -383,6 +387,37 @@
}
}
};
// TOOD: This doesn't really belong here
self.getNowPlayingNameHtml = function (nowPlayingItem) {
var topText = nowPlayingItem.Name;
if (nowPlayingItem.MediaType == 'Video') {
if (nowPlayingItem.IndexNumber != null) {
topText = nowPlayingItem.IndexNumber + " - " + topText;
}
if (nowPlayingItem.ParentIndexNumber != null) {
topText = nowPlayingItem.ParentIndexNumber + "." + topText;
}
}
var bottomText = '';
if (nowPlayingItem.Artists && nowPlayingItem.Artists.length) {
bottomText = topText;
topText = nowPlayingItem.Artists[0];
}
else if (nowPlayingItem.SeriesName || nowPlayingItem.Album) {
bottomText = topText;
topText = nowPlayingItem.SeriesName || nowPlayingItem.Album;
}
else if (nowPlayingItem.ProductionYear) {
bottomText = nowPlayingItem.ProductionYear;
}
return bottomText ? topText + '<br/>' + bottomText : topText;
};
}
window.MediaController = new mediaController();

View file

@ -327,7 +327,7 @@
}
var nowPlayingTextElement = $('.nowPlayingText', mediaControls);
var nameHtml = self.getNowPlayingNameHtml(state);
var nameHtml = MediaController.getNowPlayingNameHtml(state.NowPlayingItem);
if (nameHtml.indexOf('<br/>') != -1) {
nowPlayingTextElement.addClass('nowPlayingDoubleText');
@ -976,31 +976,8 @@
return s.Type == 'Subtitle';
});
// Get Video Poster (Code from librarybrowser.js)
var screenWidth = Math.max(screen.height, screen.width);
var posterCode = '';
if (item.BackdropImageTags && item.BackdropImageTags.length) {
posterCode = ' poster="' + ApiClient.getScaledImageUrl(item.Id, {
type: "Backdrop",
index: 0,
maxWidth: screenWidth,
tag: item.BackdropImageTags[0]
}) + '"';
}
else if (item.ParentBackdropItemId && item.ParentBackdropImageTags && item.ParentBackdropImageTags.length) {
posterCode = ' poster="' + ApiClient.getScaledImageUrl(item.ParentBackdropItemId, {
type: 'Backdrop',
index: 0,
maxWidth: screenWidth,
tag: item.ParentBackdropImageTags[0]
}) + '"';
}
var posterCode = self.getPosterUrl(item);
posterCode = posterCode ? (' poster="' + posterCode + '"') : '';
//======================================================================================>
// Create video player

View file

@ -941,35 +941,32 @@
}
self.getNowPlayingNameHtml = function (playerState) {
self.getPosterUrl = function (item) {
var nowPlayingItem = playerState.NowPlayingItem;
var topText = nowPlayingItem.Name;
var screenWidth = Math.max(screen.height, screen.width);
if (item.BackdropImageTags && item.BackdropImageTags.length) {
return ApiClient.getScaledImageUrl(item.Id, {
type: "Backdrop",
index: 0,
maxWidth: screenWidth,
tag: item.BackdropImageTags[0]
});
}
else if (item.ParentBackdropItemId && item.ParentBackdropImageTags && item.ParentBackdropImageTags.length) {
return ApiClient.getScaledImageUrl(item.ParentBackdropItemId, {
type: 'Backdrop',
index: 0,
maxWidth: screenWidth,
tag: item.ParentBackdropImageTags[0]
});
if (nowPlayingItem.MediaType == 'Video') {
if (nowPlayingItem.IndexNumber != null) {
topText = nowPlayingItem.IndexNumber + " - " + topText;
}
if (nowPlayingItem.ParentIndexNumber != null) {
topText = nowPlayingItem.ParentIndexNumber + "." + topText;
}
}
var bottomText = '';
if (nowPlayingItem.Artists && nowPlayingItem.Artists.length) {
bottomText = topText;
topText = nowPlayingItem.Artists[0];
}
else if (nowPlayingItem.SeriesName || nowPlayingItem.Album) {
bottomText = topText;
topText = nowPlayingItem.SeriesName || nowPlayingItem.Album;
}
else if (nowPlayingItem.ProductionYear) {
bottomText = nowPlayingItem.ProductionYear;
}
return bottomText ? topText + '<br/>' + bottomText : topText;
return null;
};
self.displayContent = function (options) {
@ -1676,6 +1673,7 @@
this.src = audioUrl;
this.volume = initialVolume;
this.poster = self.getPosterUrl(item);
this.play();
}).on("volumechange.mediaplayerevent", function () {

View file

@ -287,7 +287,7 @@
var currentImgUrl;
function updateNowPlayingInfo(state) {
var nameHtml = MediaPlayer.getNowPlayingNameHtml(state) || '';
var nameHtml = MediaController.getNowPlayingNameHtml(state.NowPlayingItem) || '';
if (nameHtml.indexOf('<br/>') != -1) {
nowPlayingTextElement.addClass('nowPlayingDoubleText');

View file

@ -521,7 +521,7 @@
var item = state.NowPlayingItem;
$('.itemName', page).html(item ? MediaPlayer.getNowPlayingNameHtml(state) : '');
$('.itemName', page).html(item ? MediaController.getNowPlayingNameHtml(item) : '');
var url;

View file

@ -175,9 +175,12 @@
index = Math.max(index || 0, 0);
$.swipebox(slideshowItems, {
initialIndexOnArray: index,
hideBarsDelay: 30000
Dashboard.loadSwipebox().done(function() {
$.swipebox(slideshowItems, {
initialIndexOnArray: index,
hideBarsDelay: 30000
});
});
}

View file

@ -1460,6 +1460,20 @@ var Dashboard = {
deviceName: deviceName,
deviceId: deviceId
};
},
loadSwipebox: function() {
var deferred = DeferredBuilder.Deferred();
require([
'thirdparty/swipebox-master/js/jquery.swipebox.min',
'css!thirdparty/swipebox-master/css/swipebox.min'
], function () {
deferred.resolve();
});
return deferred.promise();
}
};
@ -1583,12 +1597,16 @@ var AppInfo = {};
function initFastClick() {
FastClick.attach(document.body);
requirejs(["thirdparty/fastclick"], function (FastClick) {
// Have to work around this issue of fast click breaking the panel dismiss
$(document.body).on('touchstart', '.ui-panel-dismiss', function () {
$(this).trigger('click');
FastClick.attach(document.body);
// Have to work around this issue of fast click breaking the panel dismiss
$(document.body).on('touchstart', '.ui-panel-dismiss', function () {
$(this).trigger('click');
});
});
}
function onReady() {
@ -1725,10 +1743,17 @@ var AppInfo = {};
var apiClient = ConnectionManager.currentApiClient();
// Close the connection gracefully when possible
if (apiClient && apiClient.isWebSocketOpen() && !MediaPlayer.isPlaying()) {
if (apiClient && apiClient.isWebSocketOpen()) {
console.log('Sending close web socket command');
apiClient.closeWebSocket();
var localActivePlayers = MediaController.getPlayers().filter(function (p) {
return p.isLocalPlayer && p.isPlaying();
});
if (!localActivePlayers.length) {
console.log('Sending close web socket command');
apiClient.closeWebSocket();
}
}
});
@ -1741,6 +1766,19 @@ var AppInfo = {};
});
}
requirejs.config({
map: {
'*': {
'css': 'thirdparty/requirecss' // or whatever the path to require-css is
}
}
});
// Required since jQuery is loaded before requireJs
define('jquery', [], function () {
return jQuery;
});
setAppInfo();
createConnectionManager();

View file

@ -46,8 +46,13 @@
var val = store.getItem('enableThemeSongs-' + userId);
var localAutoPlayers = MediaController.getPlayers().filter(function (p) {
return p.isLocalPlayer && p.canAutoPlayAudio();
});
// For bandwidth
return val == '1' || (val != '0' && MediaPlayer.canAutoPlayAudio());
return val == '1' || (val != '0' && localAutoPlayers.length);
}
function getPlayer() {