1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
jellyfin-web/dashboard-ui/scripts/site.js

2549 lines
81 KiB
JavaScript
Raw Normal View History

2014-07-16 23:17:14 -04:00
(function () {
2015-12-14 10:43:03 -05:00
function onOneDocumentClick() {
2014-07-13 00:55:56 -04:00
2015-12-14 10:43:03 -05:00
document.removeEventListener('click', onOneDocumentClick);
2014-07-13 00:55:56 -04:00
2015-12-14 10:43:03 -05:00
if (window.Notification) {
Notification.requestPermission();
}
2014-10-28 19:17:55 -04:00
}
2015-12-14 10:43:03 -05:00
document.addEventListener('click', onOneDocumentClick);
2015-12-14 10:43:03 -05:00
})();
2015-12-23 12:46:01 -05:00
// Compatibility
window.Logger = {
2015-12-30 12:02:11 -05:00
log: function (msg) {
2015-12-23 12:46:01 -05:00
console.log(msg);
}
};
var Dashboard = {
2015-07-27 14:18:10 -04:00
filterHtml: function (html) {
2015-07-27 22:05:06 -04:00
// replace the first instance
html = html.replace('<!--', '');
// replace the last instance
2015-07-27 23:32:33 -04:00
var lastIndex = html.lastIndexOf('-->');
if (lastIndex != -1) {
html = html.substring(0, lastIndex) + html.substring(lastIndex + 3);
}
2015-07-27 22:05:06 -04:00
2015-07-27 14:18:10 -04:00
return Globalize.translateDocument(html, 'html');
},
2015-05-05 11:24:47 -04:00
isConnectMode: function () {
2015-05-28 19:37:43 -04:00
if (AppInfo.isNativeApp) {
2015-05-05 11:24:47 -04:00
return true;
}
2015-12-14 10:43:03 -05:00
var url = window.location.href.toLowerCase();
2015-05-05 11:24:47 -04:00
return url.indexOf('mediabrowser.tv') != -1 ||
2015-08-30 13:26:30 -04:00
url.indexOf('emby.media') != -1;
2015-05-05 11:24:47 -04:00
},
2015-05-01 14:37:01 -04:00
isRunningInCordova: function () {
2015-05-02 12:34:27 -04:00
return window.appMode == 'cordova';
2015-05-01 14:37:01 -04:00
},
2014-10-28 19:17:55 -04:00
onRequestFail: function (e, data) {
if (data.status == 401) {
var url = data.url.toLowerCase();
2015-09-23 00:00:30 -04:00
// Don't bounce to login on failures to contact our external servers
2015-10-10 20:39:30 -04:00
if (url.indexOf('emby.media') != -1 || url.indexOf('mb3admin.com') != -1) {
2015-09-23 00:00:30 -04:00
Dashboard.hideLoadingMsg();
return;
}
2015-10-02 02:14:04 -04:00
// Don't bounce if the failure is in a sync service
if (url.indexOf('/sync') != -1) {
Dashboard.hideLoadingMsg();
return;
}
2014-10-28 19:17:55 -04:00
// Bounce to the login screen, but not if a password entry fails, obviously
if (url.indexOf('/password') == -1 &&
url.indexOf('/authenticate') == -1 &&
!$($.mobile.activePage).is('.standalonePage')) {
if (data.errorCode == "ParentalControl") {
Dashboard.alert({
message: Globalize.translate('MessageLoggedOutParentalControl'),
2014-10-29 18:01:02 -04:00
callback: function () {
2014-10-28 19:17:55 -04:00
Dashboard.logout(false);
}
});
} else {
Dashboard.logout(false);
}
}
return;
2015-07-23 09:23:22 -04:00
Dashboard.hideLoadingMsg();
2014-10-28 19:17:55 -04:00
}
},
2015-09-19 22:06:56 -04:00
onPopupOpen: function () {
2015-09-17 17:26:06 -04:00
Dashboard.popupCount = (Dashboard.popupCount || 0) + 1;
document.body.classList.add('bodyWithPopupOpen');
},
2015-09-19 22:06:56 -04:00
onPopupClose: function () {
2015-09-17 17:26:06 -04:00
Dashboard.popupCount = (Dashboard.popupCount || 1) - 1;
if (!Dashboard.popupCount) {
document.body.classList.remove('bodyWithPopupOpen');
}
},
getCurrentUser: function () {
2015-12-14 10:43:03 -05:00
return window.ApiClient.getCurrentUser();
},
2015-05-20 12:28:55 -04:00
serverAddress: function () {
2014-07-07 21:41:03 -04:00
2015-05-20 12:28:55 -04:00
if (Dashboard.isConnectMode()) {
var apiClient = window.ApiClient;
2014-10-22 00:42:26 -04:00
2015-05-20 12:28:55 -04:00
if (apiClient) {
return apiClient.serverAddress();
}
2014-10-22 00:42:26 -04:00
2015-05-20 12:28:55 -04:00
return null;
2014-10-15 23:26:39 -04:00
}
2015-05-20 12:28:55 -04:00
// Try to get the server address from the browser url
// This will preserve protocol, hostname, port and subdirectory
2015-12-14 10:43:03 -05:00
var urlLower = window.location.href.toLowerCase();
2015-05-20 12:28:55 -04:00
var index = urlLower.indexOf('/web');
if (index == -1) {
index = urlLower.indexOf('/dashboard');
}
2015-02-10 22:28:34 -05:00
2015-05-20 12:28:55 -04:00
if (index != -1) {
return urlLower.substring(0, index);
}
2015-02-10 22:28:34 -05:00
2015-05-20 12:28:55 -04:00
// If the above failed, just piece it together manually
var loc = window.location;
2014-10-15 23:26:39 -04:00
2015-05-20 12:28:55 -04:00
var address = loc.protocol + '//' + loc.hostname;
2014-10-15 23:26:39 -04:00
2015-05-20 12:28:55 -04:00
if (loc.port) {
address += ':' + loc.port;
2014-10-15 23:26:39 -04:00
}
return address;
},
getCurrentUserId: function () {
2015-05-20 12:28:55 -04:00
var apiClient = window.ApiClient;
2014-03-15 16:08:06 -04:00
2015-05-20 12:28:55 -04:00
if (apiClient) {
return apiClient.getCurrentUserId();
}
2015-05-20 12:28:55 -04:00
return null;
},
2015-05-20 12:28:55 -04:00
onServerChanged: function (userId, accessToken, apiClient) {
2015-05-20 12:28:55 -04:00
apiClient = apiClient || window.ApiClient;
2014-02-08 15:02:35 -05:00
2015-05-20 12:28:55 -04:00
window.ApiClient = apiClient;
},
2015-05-21 16:53:14 -04:00
logout: function (logoutWithServer) {
2015-05-17 21:27:48 -04:00
function onLogoutDone() {
2015-05-19 15:15:40 -04:00
var loginPage;
2014-10-21 08:42:02 -04:00
2015-05-18 21:46:31 -04:00
if (Dashboard.isConnectMode()) {
loginPage = 'connectlogin.html';
window.ApiClient = null;
} else {
2015-05-19 15:15:40 -04:00
loginPage = 'login.html';
2015-05-18 21:46:31 -04:00
}
2015-05-21 16:53:14 -04:00
Dashboard.navigate(loginPage);
2015-05-17 21:27:48 -04:00
}
2014-07-13 00:55:56 -04:00
2015-05-17 21:27:48 -04:00
if (logoutWithServer === false) {
onLogoutDone();
} else {
2015-12-14 10:43:03 -05:00
ConnectionManager.logout().then(onLogoutDone);
2014-07-13 00:55:56 -04:00
}
},
2015-01-19 00:41:56 -05:00
importCss: function (url) {
2015-06-16 15:17:12 -04:00
2015-10-26 01:29:32 -04:00
var originalUrl = url;
2015-12-14 10:43:03 -05:00
url += "?v=" + AppInfo.appVersion;
2015-10-02 02:14:04 -04:00
2015-06-16 15:17:12 -04:00
if (!Dashboard.importedCss) {
Dashboard.importedCss = [];
}
if (Dashboard.importedCss.indexOf(url) != -1) {
return;
}
Dashboard.importedCss.push(url);
2015-01-19 00:41:56 -05:00
if (document.createStyleSheet) {
document.createStyleSheet(url);
2015-08-30 13:26:30 -04:00
} else {
2015-07-03 07:51:45 -04:00
var link = document.createElement('link');
link.setAttribute('rel', 'stylesheet');
2015-10-26 01:29:32 -04:00
link.setAttribute('data-url', originalUrl);
2015-07-03 07:51:45 -04:00
link.setAttribute('type', 'text/css');
link.setAttribute('href', url);
document.head.appendChild(link);
2015-01-19 00:41:56 -05:00
}
},
2015-10-26 01:29:32 -04:00
removeStylesheet: function (url) {
var elem = document.querySelector('link[data-url=\'' + url + '\']');
if (elem) {
elem.parentNode.removeChild(elem);
}
},
updateSystemInfo: function (info) {
Dashboard.lastSystemInfo = info;
2014-07-07 21:41:03 -04:00
2014-07-20 00:46:29 -04:00
Dashboard.ensureWebSocket();
if (!Dashboard.initialServerVersion) {
Dashboard.initialServerVersion = info.Version;
}
if (info.HasPendingRestart) {
Dashboard.hideDashboardVersionWarning();
2015-12-14 10:43:03 -05:00
Dashboard.getCurrentUser().then(function (currentUser) {
2014-12-20 01:06:27 -05:00
if (currentUser.Policy.IsAdministrator) {
2013-10-07 10:38:31 -04:00
Dashboard.showServerRestartWarning(info);
}
});
} else {
Dashboard.hideServerRestartWarning();
if (Dashboard.initialServerVersion != info.Version) {
2015-01-19 00:41:56 -05:00
Dashboard.showDashboardRefreshNotification();
}
}
Dashboard.showInProgressInstallations(info.InProgressInstallations);
},
showInProgressInstallations: function (installations) {
installations = installations || [];
for (var i = 0, length = installations.length; i < length; i++) {
var installation = installations[i];
var percent = installation.PercentComplete || 0;
if (percent < 100) {
Dashboard.showPackageInstallNotification(installation, "progress");
}
}
if (installations.length) {
Dashboard.ensureInstallRefreshInterval();
} else {
Dashboard.stopInstallRefreshInterval();
}
},
ensureInstallRefreshInterval: function () {
if (!Dashboard.installRefreshInterval) {
if (ApiClient.isWebSocketOpen()) {
2014-05-10 13:28:03 -04:00
ApiClient.sendWebSocketMessage("SystemInfoStart", "0,500");
}
Dashboard.installRefreshInterval = 1;
}
},
stopInstallRefreshInterval: function () {
if (Dashboard.installRefreshInterval) {
if (ApiClient.isWebSocketOpen()) {
ApiClient.sendWebSocketMessage("SystemInfoStop");
}
Dashboard.installRefreshInterval = null;
}
},
cancelInstallation: function (id) {
2015-12-14 10:43:03 -05:00
ApiClient.cancelPackageInstallation(id).then(Dashboard.refreshSystemInfoFromServer, Dashboard.refreshSystemInfoFromServer);
},
2013-10-07 10:38:31 -04:00
showServerRestartWarning: function (systemInfo) {
2015-12-30 12:02:11 -05:00
if (AppInfo.isNativeApp) {
return;
}
2014-07-16 23:17:14 -04:00
var html = '<span style="margin-right: 1em;">' + Globalize.translate('MessagePleaseRestart') + '</span>';
2013-11-28 13:27:29 -05:00
2013-10-07 10:38:31 -04:00
if (systemInfo.CanSelfRestart) {
2015-08-21 23:30:19 -04:00
html += '<paper-button raised class="submit mini" onclick="this.disabled=\'disabled\';Dashboard.restartServer();"><iron-icon icon="refresh"></iron-icon><span>' + Globalize.translate('ButtonRestart') + '</span></paper-button>';
2013-10-07 10:38:31 -04:00
}
Dashboard.showFooterNotification({ id: "serverRestartWarning", html: html, forceShow: true, allowHide: false });
},
hideServerRestartWarning: function () {
2015-06-28 10:45:21 -04:00
var elem = document.getElementById('serverRestartWarning');
if (elem) {
elem.parentNode.removeChild(elem);
}
},
2015-01-19 00:41:56 -05:00
showDashboardRefreshNotification: function () {
2015-12-30 12:02:11 -05:00
if (AppInfo.isNativeApp) {
return;
}
2014-07-16 23:17:14 -04:00
var html = '<span style="margin-right: 1em;">' + Globalize.translate('MessagePleaseRefreshPage') + '</span>';
2015-08-21 23:30:19 -04:00
html += '<paper-button raised class="submit mini" onclick="this.disabled=\'disabled\';Dashboard.reloadPage();"><iron-icon icon="refresh"></iron-icon><span>' + Globalize.translate('ButtonRefresh') + '</span></paper-button>';
2014-04-13 13:27:13 -04:00
Dashboard.showFooterNotification({ id: "dashboardVersionWarning", html: html, forceShow: true, allowHide: false });
},
reloadPage: function () {
2015-12-14 10:43:03 -05:00
var currentUrl = window.location.href.toLowerCase();
2015-05-17 21:27:48 -04:00
var newUrl;
2013-11-28 13:27:29 -05:00
// If they're on a plugin config page just go back to the dashboard
// The plugin may not have been loaded yet, or could have been uninstalled
if (currentUrl.indexOf('configurationpage') != -1) {
2015-05-17 21:27:48 -04:00
newUrl = "dashboard.html";
} else {
2015-12-14 10:43:03 -05:00
newUrl = window.location.href;
}
2015-05-17 21:27:48 -04:00
window.location.href = newUrl;
},
hideDashboardVersionWarning: function () {
2015-06-28 10:45:21 -04:00
var elem = document.getElementById('dashboardVersionWarning');
if (elem) {
elem.parentNode.removeChild(elem);
}
},
showFooterNotification: function (options) {
var removeOnHide = !options.id;
options.id = options.id || "notification" + new Date().getTime() + parseInt(Math.random());
2015-12-14 10:43:03 -05:00
if (!document.querySelector(".footer")) {
var footerHtml = '<div id="footer" class="footer" data-theme="b" class="ui-bar-b">';
footerHtml += '<div id="footerNotifications"></div>';
footerHtml += '</div>';
$(document.body).append(footerHtml);
}
2015-05-07 18:27:01 -04:00
var footer = $(".footer").css("top", "initial").show();
var parentElem = $('#footerNotifications', footer);
var elem = $('#' + options.id, parentElem);
if (!elem.length) {
elem = $('<p id="' + options.id + '" class="footerNotification"></p>').appendTo(parentElem);
}
2015-10-04 14:10:50 -04:00
var onclick = removeOnHide ? "jQuery(\"#" + options.id + "\").trigger(\"notification.remove\").remove();" : "jQuery(\"#" + options.id + "\").trigger(\"notification.hide\").hide();";
if (options.allowHide !== false) {
options.html += "<span style='margin-left: 1em;'><paper-button class='submit' onclick='" + onclick + "'>" + Globalize.translate('ButtonHide') + "</paper-button></span>";
}
if (options.forceShow) {
2016-02-24 11:52:25 -05:00
elem.show();
}
2015-12-14 10:43:03 -05:00
elem.html(options.html);
if (options.timeout) {
setTimeout(function () {
if (removeOnHide) {
elem.trigger("notification.remove").remove();
} else {
elem.trigger("notification.hide").hide();
}
}, options.timeout);
}
footer.on("notification.remove notification.hide", function (e) {
setTimeout(function () { // give the DOM time to catch up
if (!parentElem.html()) {
2016-02-24 11:52:25 -05:00
footer.hide();
}
}, 50);
});
},
getConfigurationPageUrl: function (name) {
return "ConfigurationPage?name=" + encodeURIComponent(name);
},
2015-12-14 10:43:03 -05:00
navigate: function (url, preserveQueryString) {
2015-05-13 00:55:19 -04:00
if (!url) {
throw new Error('url cannot be null or empty');
}
2014-04-08 22:12:17 -04:00
var queryString = getWindowLocationSearch();
if (preserveQueryString && queryString) {
url += queryString;
}
2015-05-20 13:29:26 -04:00
var options = {};
$.mobile.changePage(url, options);
},
showLoadingMsg: function () {
2015-06-16 13:37:49 -04:00
2015-12-14 10:43:03 -05:00
Dashboard.loadingVisible = true;
2015-06-16 13:37:49 -04:00
2016-02-16 11:15:36 -05:00
require(['loading'], function (loading) {
if (Dashboard.loadingVisible) {
loading.show();
} else {
loading.hide();
}
});
},
hideLoadingMsg: function () {
2015-06-16 13:37:49 -04:00
2015-12-14 10:43:03 -05:00
Dashboard.loadingVisible = false;
2016-02-16 11:15:36 -05:00
require(['loading'], function (loading) {
if (Dashboard.loadingVisible) {
loading.show();
} else {
loading.hide();
}
});
},
2015-05-06 23:11:51 -04:00
getModalLoadingMsg: function () {
2015-12-14 10:43:03 -05:00
var elem = document.querySelector('.modalLoading');
2015-05-06 23:11:51 -04:00
2015-12-14 10:43:03 -05:00
if (!elem) {
2015-05-06 23:11:51 -04:00
2015-12-14 10:43:03 -05:00
elem = document.createElement('modalLoading');
elem.classList.add('modalLoading');
elem.classList.add('hide');
document.body.appendChild(elem);
2015-05-06 23:11:51 -04:00
}
return elem;
},
showModalLoadingMsg: function () {
2015-12-14 10:43:03 -05:00
Dashboard.getModalLoadingMsg().classList.remove('hide');
2015-07-23 09:23:22 -04:00
Dashboard.showLoadingMsg();
2015-05-06 23:11:51 -04:00
},
hideModalLoadingMsg: function () {
2015-12-14 10:43:03 -05:00
Dashboard.getModalLoadingMsg().classList.add('hide');
2015-05-06 23:11:51 -04:00
Dashboard.hideLoadingMsg();
},
processPluginConfigurationUpdateResult: function () {
Dashboard.hideLoadingMsg();
2016-02-25 01:38:12 -05:00
require(['toast'], function (toast) {
toast(Globalize.translate('MessageSettingsSaved'));
});
},
processServerConfigurationUpdateResult: function (result) {
Dashboard.hideLoadingMsg();
2016-02-25 01:38:12 -05:00
require(['toast'], function (toast) {
toast(Globalize.translate('MessageSettingsSaved'));
});
},
2015-05-01 14:37:01 -04:00
alert: function (options) {
if (typeof options == "string") {
2016-02-16 11:15:36 -05:00
require(['toast'], function (toast) {
2015-05-01 14:37:01 -04:00
2016-02-16 11:15:36 -05:00
toast({
text: options
});
2015-12-14 10:43:03 -05:00
2015-06-16 13:37:49 -04:00
});
2015-05-01 14:37:01 -04:00
return;
}
2016-02-26 15:29:27 -05:00
require(['alert'], function (alert) {
alert({
title: options.title || Globalize.translate('HeaderAlert'),
text: options.message
}).then(options.callback || function () { });
2015-12-14 10:43:03 -05:00
});
},
refreshSystemInfoFromServer: function () {
2015-05-20 12:28:55 -04:00
var apiClient = ApiClient;
2015-05-21 16:53:14 -04:00
if (apiClient && apiClient.accessToken()) {
2015-07-13 17:26:11 -04:00
if (AppInfo.enableFooterNotifications) {
2015-12-14 10:43:03 -05:00
apiClient.getSystemInfo().then(function (info) {
2014-07-07 21:41:03 -04:00
2015-05-07 18:27:01 -04:00
Dashboard.updateSystemInfo(info);
});
} else {
Dashboard.ensureWebSocket();
}
2014-07-07 21:41:03 -04:00
}
},
restartServer: function () {
Dashboard.suppressAjaxErrors = true;
Dashboard.showLoadingMsg();
2015-12-14 10:43:03 -05:00
ApiClient.restartServer().then(function () {
setTimeout(function () {
Dashboard.reloadPageWhenServerAvailable();
}, 250);
2015-12-14 10:43:03 -05:00
}, function () {
Dashboard.suppressAjaxErrors = false;
});
},
reloadPageWhenServerAvailable: function (retryCount) {
// Don't use apiclient method because we don't want it reporting authentication under the old version
2015-12-14 10:43:03 -05:00
ApiClient.getJSON(ApiClient.getUrl("System/Info")).then(function (info) {
// If this is back to false, the restart completed
if (!info.HasPendingRestart) {
Dashboard.reloadPage();
} else {
Dashboard.retryReload(retryCount);
}
2015-12-14 10:43:03 -05:00
}, function () {
Dashboard.retryReload(retryCount);
});
},
retryReload: function (retryCount) {
setTimeout(function () {
retryCount = retryCount || 0;
retryCount++;
if (retryCount < 10) {
Dashboard.reloadPageWhenServerAvailable(retryCount);
} else {
Dashboard.suppressAjaxErrors = false;
}
}, 500);
},
2015-06-10 09:37:07 -04:00
showUserFlyout: function () {
2016-02-14 15:38:19 -05:00
Dashboard.navigate('mypreferencesmenu.html?userId=' + ApiClient.getCurrentUserId());
2015-06-10 09:37:07 -04:00
},
updateUserFlyout: function (elem, user) {
var html = '';
var imgWidth = 48;
2016-02-26 12:15:06 -05:00
if (user.imageUrl) {
2015-06-10 09:37:07 -04:00
var url = user.imageUrl;
if (user.supportsImageParams) {
url += "&width=" + (imgWidth * Math.max(window.devicePixelRatio || 1, 2));
}
2015-06-27 23:29:50 -04:00
html += '<div style="background-image:url(\'' + url + '\');width:' + imgWidth + 'px;height:' + imgWidth + 'px;background-size:contain;background-repeat:no-repeat;background-position:center center;border-radius:1000px;vertical-align:middle;margin-right:.8em;display:inline-block;"></div>';
2015-06-10 09:37:07 -04:00
}
html += user.name;
2015-12-14 10:43:03 -05:00
var userHeader = elem.querySelector('.userHeader');
userHeader.innerHTML = html;
ImageLoader.lazyChildren(userHeader);
2015-06-10 09:37:07 -04:00
html = '';
2015-12-14 10:43:03 -05:00
if (user.localUser) {
2015-07-28 15:42:24 -04:00
html += '<p><a data-mini="true" data-role="button" href="mypreferencesmenu.html?userId=' + user.localUser.Id + '" data-icon="gear">' + Globalize.translate('ButtonSettings') + '</button></a>';
2015-06-10 09:37:07 -04:00
}
2015-12-14 10:43:03 -05:00
$('.preferencesContainer', elem).html(html);
2015-06-10 09:37:07 -04:00
},
getPluginSecurityInfo: function () {
2015-05-19 15:15:40 -04:00
var apiClient = ApiClient;
if (!apiClient) {
2016-02-22 13:25:45 -05:00
return Promise.reject();
2015-12-14 10:43:03 -05:00
}
2015-12-14 10:43:03 -05:00
var cachedInfo = Dashboard.pluginSecurityInfo;
if (cachedInfo) {
2016-02-22 13:25:45 -05:00
return Promise.resolve(cachedInfo);
}
2015-12-14 10:43:03 -05:00
return apiClient.ajax({
type: "GET",
url: apiClient.getUrl("Plugins/SecurityInfo"),
dataType: 'json',
error: function () {
// Don't show normal dashboard errors
}
}).then(function (result) {
Dashboard.pluginSecurityInfo = result;
return result;
});
},
resetPluginSecurityInfo: function () {
2015-12-14 10:43:03 -05:00
Dashboard.pluginSecurityInfo = null;
},
2014-06-22 01:52:31 -04:00
ensureHeader: function (page) {
2015-06-28 10:45:21 -04:00
if (page.classList.contains('standalonePage') && !page.classList.contains('noHeaderPage')) {
2014-06-22 01:52:31 -04:00
Dashboard.renderHeader(page);
}
},
2014-06-22 01:52:31 -04:00
renderHeader: function (page) {
2015-06-28 10:45:21 -04:00
var header = page.querySelector('.header');
2013-04-23 15:17:21 -04:00
2015-06-28 10:45:21 -04:00
if (!header) {
2014-06-22 01:52:31 -04:00
var headerHtml = '';
2013-04-22 10:44:11 -04:00
headerHtml += '<div class="header">';
2015-01-11 15:31:09 -05:00
headerHtml += '<a class="logo" href="index.html" style="text-decoration:none;font-size: 22px;">';
2015-06-28 10:45:21 -04:00
if (page.classList.contains('standalonePage')) {
2015-01-11 15:31:09 -05:00
headerHtml += '<img class="imgLogoIcon" src="css/images/mblogoicon.png" />';
2015-03-21 14:12:12 -04:00
headerHtml += '<span class="logoLibraryMenuButtonText">EMBY</span>';
2013-04-01 01:08:29 -04:00
}
headerHtml += '</a>';
2013-12-27 00:08:37 -05:00
2013-04-22 10:44:11 -04:00
headerHtml += '</div>';
2015-06-28 10:45:21 -04:00
$(page).prepend(headerHtml);
}
},
2013-05-10 08:18:07 -04:00
2015-06-21 17:31:21 -04:00
getToolsMenuHtml: function (page) {
2015-06-21 17:31:21 -04:00
var items = Dashboard.getToolsMenuLinks(page);
2015-06-21 17:31:21 -04:00
var i, length, item;
var menuHtml = '';
2015-06-21 17:31:21 -04:00
for (i = 0, length = items.length; i < length; i++) {
2015-06-21 17:31:21 -04:00
item = items[i];
2015-01-18 14:53:34 -05:00
2015-06-21 17:31:21 -04:00
if (item.divider) {
menuHtml += "<div class='sidebarDivider'></div>";
}
2015-06-21 17:31:21 -04:00
if (item.href) {
2015-05-31 14:22:51 -04:00
2015-06-21 17:31:21 -04:00
var style = item.color ? ' style="color:' + item.color + '"' : '';
2015-01-18 14:53:34 -05:00
2015-06-21 17:31:21 -04:00
if (item.selected) {
menuHtml += '<a class="sidebarLink selectedSidebarLink" href="' + item.href + '">';
2015-01-18 14:53:34 -05:00
} else {
2015-06-21 17:31:21 -04:00
menuHtml += '<a class="sidebarLink" href="' + item.href + '">';
}
2015-01-18 23:29:57 -05:00
2015-06-21 17:31:21 -04:00
var icon = item.icon;
if (icon) {
menuHtml += '<iron-icon icon="' + icon + '" class="sidebarLinkIcon"' + style + '></iron-icon>';
}
2015-06-21 17:31:21 -04:00
menuHtml += '<span class="sidebarLinkText">';
menuHtml += item.name;
menuHtml += '</span>';
menuHtml += '</a>';
} else {
2015-06-21 17:31:21 -04:00
menuHtml += '<div class="sidebarHeader">';
menuHtml += item.name;
menuHtml += '</div>';
}
}
2015-06-21 17:31:21 -04:00
return menuHtml;
},
2013-12-27 00:08:37 -05:00
2015-06-21 17:31:21 -04:00
ensureToolsMenu: function (page) {
2013-12-27 00:08:37 -05:00
2015-06-28 10:45:21 -04:00
var sidebar = page.querySelector('.toolsSidebar');
2015-05-31 17:07:44 -04:00
2015-06-28 10:45:21 -04:00
if (!sidebar) {
2015-05-31 17:07:44 -04:00
2015-06-21 17:31:21 -04:00
var html = '<div class="content-secondary toolsSidebar">';
2015-05-31 17:07:44 -04:00
2015-06-21 17:31:21 -04:00
html += '<div class="sidebarLinks">';
2015-05-31 17:07:44 -04:00
2015-06-21 17:31:21 -04:00
html += Dashboard.getToolsMenuHtml(page);
// sidebarLinks
2015-05-31 17:07:44 -04:00
html += '</div>';
2015-06-21 17:31:21 -04:00
// content-secondary
2013-12-27 00:08:37 -05:00
html += '</div>';
2014-07-26 13:30:15 -04:00
$('.content-primary', page).before(html);
}
},
getToolsMenuLinks: function (page) {
2015-06-28 10:45:21 -04:00
var pageElem = page;
2015-06-28 10:45:21 -04:00
var isServicesPage = page.classList.contains('appServicesPage');
var context = getParameterByName('context');
return [{
2014-07-16 23:17:14 -04:00
name: Globalize.translate('TabServer'),
href: "dashboard.html",
2015-06-28 10:45:21 -04:00
selected: page.classList.contains("dashboardHomePage"),
2015-06-21 17:31:21 -04:00
icon: 'dashboard',
2015-01-18 14:53:34 -05:00
color: '#38c'
2014-10-11 16:38:13 -04:00
}, {
name: Globalize.translate('TabDevices'),
href: "devices.html",
2015-06-28 10:45:21 -04:00
selected: page.classList.contains("devicesPage"),
2015-06-21 17:31:21 -04:00
icon: 'tablet',
2015-01-18 14:53:34 -05:00
color: '#ECA403'
2014-07-26 13:30:15 -04:00
}, {
name: Globalize.translate('TabUsers'),
href: "userprofiles.html",
2015-06-28 10:45:21 -04:00
selected: page.classList.contains("userProfilesPage"),
2015-06-21 17:31:21 -04:00
icon: 'people',
2015-01-18 14:53:34 -05:00
color: '#679C34'
}, {
2014-07-16 23:17:14 -04:00
name: Globalize.translate('TabLibrary'),
2013-12-25 22:44:26 -05:00
divider: true,
href: "library.html",
2015-10-26 14:23:46 -04:00
selected: page.classList.contains("librarySectionPage"),
2015-06-21 17:31:21 -04:00
icon: 'video-library'
}, {
2014-07-16 23:17:14 -04:00
name: Globalize.translate('TabMetadata'),
href: "metadata.html",
2015-06-28 10:45:21 -04:00
selected: page.classList.contains('metadataConfigurationPage'),
2015-06-23 18:13:06 -04:00
icon: 'insert-drive-file'
2014-01-22 18:52:01 -05:00
}, {
2014-09-22 17:56:54 -04:00
name: Globalize.translate('TabPlayback'),
href: "playbackconfiguration.html",
2015-06-28 10:45:21 -04:00
selected: page.classList.contains('playbackConfigurationPage'),
2015-06-21 17:31:21 -04:00
icon: 'play-circle-filled'
}, {
name: Globalize.translate('TabSync'),
href: "syncactivity.html",
2015-06-28 10:45:21 -04:00
selected: page.classList.contains('syncConfigurationPage') || (isServicesPage && context == 'sync'),
2015-09-20 12:16:06 -04:00
icon: 'sync'
2014-09-22 17:56:54 -04:00
}, {
divider: true,
2015-01-18 14:53:34 -05:00
name: Globalize.translate('TabExtras')
}, {
2014-07-16 23:17:14 -04:00
name: Globalize.translate('TabAutoOrganize'),
2014-01-22 18:52:01 -05:00
href: "autoorganizelog.html",
2015-06-28 10:45:21 -04:00
selected: page.classList.contains("organizePage"),
2015-06-21 17:31:21 -04:00
icon: 'folder',
2015-01-18 14:53:34 -05:00
color: '#01C0DD'
2014-06-01 15:41:35 -04:00
}, {
2014-07-16 23:17:14 -04:00
name: Globalize.translate('TabDLNA'),
2014-03-10 13:38:53 -04:00
href: "dlnasettings.html",
2015-06-28 10:45:21 -04:00
selected: page.classList.contains("dlnaPage"),
2015-06-21 17:31:21 -04:00
icon: 'tv',
2015-01-18 14:53:34 -05:00
color: '#E5342E'
2014-01-12 11:55:38 -05:00
}, {
2014-07-16 23:17:14 -04:00
name: Globalize.translate('TabLiveTV'),
2014-01-22 15:46:01 -05:00
href: "livetvstatus.html",
2015-06-28 10:45:21 -04:00
selected: page.classList.contains("liveTvSettingsPage") || (isServicesPage && context == 'livetv'),
2015-06-21 17:31:21 -04:00
icon: 'live-tv',
2015-01-18 14:53:34 -05:00
color: '#293AAE'
}, {
name: Globalize.translate('TabNotifications'),
href: "notificationsettings.html",
2015-06-28 10:45:21 -04:00
selected: page.classList.contains("notificationConfigurationPage"),
2015-06-21 17:31:21 -04:00
icon: 'notifications',
2015-01-18 14:53:34 -05:00
color: 'brown'
2014-03-25 17:13:55 -04:00
}, {
2014-07-16 23:17:14 -04:00
name: Globalize.translate('TabPlugins'),
2014-03-25 17:13:55 -04:00
href: "plugins.html",
2015-06-28 10:45:21 -04:00
selected: page.classList.contains("pluginConfigurationPage"),
2015-06-21 17:31:21 -04:00
icon: 'add-shopping-cart',
2015-01-18 14:53:34 -05:00
color: '#9D22B1'
}, {
2013-12-25 22:44:26 -05:00
divider: true,
2015-01-18 14:53:34 -05:00
name: Globalize.translate('TabExpert')
}, {
name: Globalize.translate('TabAdvanced'),
href: "advanced.html",
2015-06-28 10:45:21 -04:00
selected: page.classList.contains("advancedConfigurationPage"),
2015-06-21 17:31:21 -04:00
icon: 'settings',
2015-01-18 14:53:34 -05:00
color: '#F16834'
}, {
name: Globalize.translate('TabScheduledTasks'),
href: "scheduledtasks.html",
2015-06-28 10:45:21 -04:00
selected: page.classList.contains("scheduledTasksConfigurationPage"),
2015-06-21 17:31:21 -04:00
icon: 'schedule',
2015-01-18 14:53:34 -05:00
color: '#38c'
}, {
2014-07-16 23:17:14 -04:00
name: Globalize.translate('TabHelp'),
2015-01-18 14:53:34 -05:00
divider: true,
href: "support.html",
2015-01-18 14:53:34 -05:00
selected: pageElem.id == "supportPage" || pageElem.id == "logPage" || pageElem.id == "supporterPage" || pageElem.id == "supporterKeyPage" || pageElem.id == "aboutPage",
2015-06-21 17:31:21 -04:00
icon: 'help',
2015-01-18 14:53:34 -05:00
color: '#679C34'
}];
},
2014-07-20 00:46:29 -04:00
ensureWebSocket: function () {
2014-10-27 17:45:50 -04:00
if (ApiClient.isWebSocketOpenOrConnecting() || !ApiClient.isWebSocketSupported()) {
return;
}
2014-10-22 00:42:26 -04:00
ApiClient.openWebSocket();
2015-05-07 18:27:01 -04:00
if (!Dashboard.isConnectMode()) {
ApiClient.reportCapabilities(Dashboard.capabilities());
}
},
2014-04-27 21:57:29 -04:00
processGeneralCommand: function (cmd) {
// Full list
// https://github.com/MediaBrowser/MediaBrowser/blob/master/MediaBrowser.Model/Session/GeneralCommand.cs#L23
2014-05-06 22:28:19 -04:00
2014-04-30 23:24:55 -04:00
switch (cmd.Name) {
2014-05-06 22:28:19 -04:00
2014-04-30 23:24:55 -04:00
case 'GoHome':
Dashboard.navigate('index.html');
break;
case 'GoToSettings':
Dashboard.navigate('dashboard.html');
break;
case 'DisplayContent':
Dashboard.onBrowseCommand(cmd.Arguments);
break;
case 'GoToSearch':
2015-12-14 10:43:03 -05:00
Search.showSearchPanel();
2014-04-30 23:24:55 -04:00
break;
2014-05-08 16:09:53 -04:00
case 'DisplayMessage':
{
var args = cmd.Arguments;
2015-12-30 12:02:11 -05:00
if (args.TimeoutMs && window.Notification && Notification.permission === "granted") {
var notification = {
title: args.Header,
body: args.Text,
vibrate: true,
timeout: args.TimeoutMs
};
var notif = new Notification(notification.title, notification);
if (notif.show) {
notif.show();
}
if (notification.timeout) {
setTimeout(function () {
if (notif.close) {
notif.close();
}
else if (notif.cancel) {
notif.cancel();
}
}, notification.timeout);
}
2014-05-08 16:09:53 -04:00
}
else {
2015-05-21 16:53:14 -04:00
Dashboard.alert({ title: args.Header, message: args.Text });
2014-05-08 16:09:53 -04:00
}
break;
}
2014-04-30 23:24:55 -04:00
case 'VolumeUp':
case 'VolumeDown':
case 'Mute':
case 'Unmute':
case 'ToggleMute':
case 'SetVolume':
case 'SetAudioStreamIndex':
case 'SetSubtitleStreamIndex':
case 'ToggleFullscreen':
2015-07-26 17:02:23 -04:00
case 'SetRepeatMode':
2014-04-30 23:24:55 -04:00
break;
default:
2015-12-23 12:46:01 -05:00
console.log('Unrecognized command: ' + cmd.Name);
2014-04-30 23:24:55 -04:00
break;
2014-04-27 21:57:29 -04:00
}
},
2013-03-28 01:19:58 -04:00
onWebSocketMessageReceived: function (e, data) {
2013-03-28 01:19:58 -04:00
var msg = data;
2013-03-31 21:52:07 -04:00
if (msg.MessageType === "LibraryChanged") {
Dashboard.processLibraryUpdateNotification(msg.Data);
}
2013-09-05 13:26:03 -04:00
else if (msg.MessageType === "ServerShuttingDown") {
Dashboard.hideServerRestartWarning();
}
else if (msg.MessageType === "ServerRestarting") {
Dashboard.hideServerRestartWarning();
}
else if (msg.MessageType === "SystemInfo") {
Dashboard.updateSystemInfo(msg.Data);
}
2013-03-28 01:19:58 -04:00
else if (msg.MessageType === "RestartRequired") {
Dashboard.updateSystemInfo(msg.Data);
}
else if (msg.MessageType === "PackageInstallationCompleted") {
2015-12-14 10:43:03 -05:00
Dashboard.getCurrentUser().then(function (currentUser) {
2014-12-20 01:06:27 -05:00
if (currentUser.Policy.IsAdministrator) {
Dashboard.showPackageInstallNotification(msg.Data, "completed");
Dashboard.refreshSystemInfoFromServer();
}
});
}
else if (msg.MessageType === "PackageInstallationFailed") {
2015-12-14 10:43:03 -05:00
Dashboard.getCurrentUser().then(function (currentUser) {
2014-12-20 01:06:27 -05:00
if (currentUser.Policy.IsAdministrator) {
Dashboard.showPackageInstallNotification(msg.Data, "failed");
Dashboard.refreshSystemInfoFromServer();
}
});
}
else if (msg.MessageType === "PackageInstallationCancelled") {
2015-12-14 10:43:03 -05:00
Dashboard.getCurrentUser().then(function (currentUser) {
2014-12-20 01:06:27 -05:00
if (currentUser.Policy.IsAdministrator) {
Dashboard.showPackageInstallNotification(msg.Data, "cancelled");
Dashboard.refreshSystemInfoFromServer();
}
});
}
2015-05-20 12:28:55 -04:00
else if (msg.MessaapiclientcgeType === "PackageInstalling") {
2015-12-14 10:43:03 -05:00
Dashboard.getCurrentUser().then(function (currentUser) {
2014-12-20 01:06:27 -05:00
if (currentUser.Policy.IsAdministrator) {
Dashboard.showPackageInstallNotification(msg.Data, "progress");
Dashboard.refreshSystemInfoFromServer();
}
});
}
2014-03-31 17:04:22 -04:00
else if (msg.MessageType === "GeneralCommand") {
2014-03-31 17:04:22 -04:00
var cmd = msg.Data;
2014-12-16 00:01:57 -05:00
// Media Controller should catch this
//Dashboard.processGeneralCommand(cmd);
}
2013-05-10 08:18:07 -04:00
},
onBrowseCommand: function (cmd) {
var url;
2013-05-25 20:53:51 -04:00
var type = (cmd.ItemType || "").toLowerCase();
2013-05-10 08:18:07 -04:00
if (type == "genre") {
2015-08-19 00:08:03 -04:00
url = "itemdetails.html?id=" + cmd.ItemId;
2013-05-10 08:18:07 -04:00
}
2013-06-10 23:31:00 -04:00
else if (type == "musicgenre") {
2015-08-19 00:08:03 -04:00
url = "itemdetails.html?id=" + cmd.ItemId;
2013-06-10 23:31:00 -04:00
}
2013-07-01 13:17:33 -04:00
else if (type == "gamegenre") {
2015-08-19 00:08:03 -04:00
url = "itemdetails.html?id=" + cmd.ItemId;
2013-07-01 13:17:33 -04:00
}
2013-05-10 08:18:07 -04:00
else if (type == "studio") {
2015-08-19 00:08:03 -04:00
url = "itemdetails.html?id=" + cmd.ItemId;
2013-05-10 08:18:07 -04:00
}
else if (type == "person") {
2015-08-19 00:08:03 -04:00
url = "itemdetails.html?id=" + cmd.ItemId;
2013-05-10 08:18:07 -04:00
}
2013-11-21 15:48:26 -05:00
else if (type == "musicartist") {
2015-08-19 00:08:03 -04:00
url = "itemdetails.html?id=" + cmd.ItemId;
2013-05-10 08:18:07 -04:00
}
2013-05-10 08:18:07 -04:00
if (url) {
Dashboard.navigate(url);
return;
}
2015-12-14 10:43:03 -05:00
ApiClient.getItem(Dashboard.getCurrentUserId(), cmd.ItemId).then(function (item) {
2013-05-10 08:18:07 -04:00
2014-07-16 23:17:14 -04:00
Dashboard.navigate(LibraryBrowser.getHref(item, null, ''));
2013-05-10 08:18:07 -04:00
});
},
showPackageInstallNotification: function (installation, status) {
2015-12-30 12:02:11 -05:00
if (AppInfo.isNativeApp) {
return;
}
var html = '';
if (status == 'completed') {
html += '<img src="css/images/notifications/done.png" class="notificationIcon" />';
}
else if (status == 'cancelled') {
html += '<img src="css/images/notifications/info.png" class="notificationIcon" />';
}
else if (status == 'failed') {
html += '<img src="css/images/notifications/error.png" class="notificationIcon" />';
}
else if (status == 'progress') {
html += '<img src="css/images/notifications/download.png" class="notificationIcon" />';
}
html += '<span style="margin-right: 1em;">';
if (status == 'completed') {
2014-07-16 23:17:14 -04:00
html += Globalize.translate('LabelPackageInstallCompleted').replace('{0}', installation.Name + ' ' + installation.Version);
}
else if (status == 'cancelled') {
2014-07-16 23:17:14 -04:00
html += Globalize.translate('LabelPackageInstallCancelled').replace('{0}', installation.Name + ' ' + installation.Version);
}
else if (status == 'failed') {
2014-07-16 23:17:14 -04:00
html += Globalize.translate('LabelPackageInstallFailed').replace('{0}', installation.Name + ' ' + installation.Version);
}
else if (status == 'progress') {
2014-07-16 23:17:14 -04:00
html += Globalize.translate('LabelInstallingPackage').replace('{0}', installation.Name + ' ' + installation.Version);
}
html += '</span>';
if (status == 'progress') {
var percentComplete = Math.round(installation.PercentComplete || 0);
html += '<progress style="margin-right: 1em;" max="100" value="' + percentComplete + '" title="' + percentComplete + '%">';
html += '' + percentComplete + '%';
html += '</progress>';
if (percentComplete < 100) {
2015-08-21 23:30:19 -04:00
html += '<paper-button raised class="cancelDark mini" onclick="this.disabled=\'disabled\';Dashboard.cancelInstallation(\'' + installation.Id + '\');"><iron-icon icon="cancel"></iron-icon><span>' + Globalize.translate('ButtonCancel') + '</span></paper-button>';
}
}
var timeout = 0;
if (status == 'cancelled') {
timeout = 2000;
}
var forceShow = status != "progress";
var allowHide = status != "progress" && status != 'cancelled';
Dashboard.showFooterNotification({ html: html, id: installation.Id, timeout: timeout, forceShow: forceShow, allowHide: allowHide });
},
processLibraryUpdateNotification: function (data) {
var newItems = data.ItemsAdded;
2013-05-10 08:18:07 -04:00
2015-12-30 12:02:11 -05:00
if (!newItems.length || AppInfo.isNativeApp || !window.Notification || Notification.permission !== "granted") {
return;
}
2013-04-15 14:45:58 -04:00
ApiClient.getItems(Dashboard.getCurrentUserId(), {
2013-04-19 18:09:21 -04:00
2013-04-15 14:45:58 -04:00
Recursive: true,
2013-05-18 17:47:50 -04:00
Limit: 3,
2013-04-15 19:45:09 -04:00
Filters: "IsNotFolder",
2013-04-15 14:45:58 -04:00
SortBy: "DateCreated",
SortOrder: "Descending",
ImageTypes: "Primary",
Ids: newItems.join(',')
2013-04-19 18:09:21 -04:00
2015-12-14 10:43:03 -05:00
}).then(function (result) {
2013-04-15 14:45:58 -04:00
var items = result.Items;
for (var i = 0, length = Math.min(items.length, 2) ; i < length; i++) {
var item = items[i];
var notification = {
2013-04-15 14:45:58 -04:00
title: "New " + item.Type,
body: item.Name,
2015-12-30 12:02:11 -05:00
timeout: 15000,
vibrate: true,
data: {
options: {
url: LibraryBrowser.getHref(item)
}
}
2013-04-15 14:45:58 -04:00
};
var imageTags = item.ImageTags || {};
2013-04-19 18:09:21 -04:00
2013-04-15 14:45:58 -04:00
if (imageTags.Primary) {
notification.icon = ApiClient.getScaledImageUrl(item.Id, {
width: 60,
2013-04-15 14:45:58 -04:00
tag: imageTags.Primary,
type: "Primary"
});
}
2015-12-30 12:02:11 -05:00
var notif = new Notification(notification.title, notification);
2015-12-14 10:43:03 -05:00
2015-12-30 12:02:11 -05:00
if (notif.show) {
notif.show();
}
2015-12-14 10:43:03 -05:00
2015-12-30 12:02:11 -05:00
if (notification.timeout) {
setTimeout(function () {
2015-12-14 10:43:03 -05:00
2015-12-30 12:02:11 -05:00
if (notif.close) {
notif.close();
}
else if (notif.cancel) {
notif.cancel();
}
}, notification.timeout);
2015-12-14 10:43:03 -05:00
}
}
});
},
ensurePageTitle: function (page) {
2015-06-28 10:45:21 -04:00
if (!page.classList.contains('type-interior')) {
return;
}
2015-06-28 10:45:21 -04:00
var pageElem = page;
if (pageElem.querySelector('.pageTitle')) {
return;
}
2015-06-28 10:45:21 -04:00
var parent = pageElem.querySelector('.content-primary');
2015-06-28 10:45:21 -04:00
if (!parent) {
parent = pageElem.getElementsByClassName('ui-content')[0];
}
2015-06-28 10:45:21 -04:00
var helpUrl = pageElem.getAttribute('data-helpurl');
2014-12-22 23:53:52 -05:00
var html = '<div>';
html += '<h1 class="pageTitle" style="display:inline-block;">' + (document.title || '&nbsp;') + '</h1>';
if (helpUrl) {
2015-08-17 12:52:56 -04:00
html += '<a href="' + helpUrl + '" target="_blank" class="clearLink" style="margin-top:-10px;display:inline-block;vertical-align:middle;margin-left:1em;"><paper-button raised class="secondary mini"><iron-icon icon="info"></iron-icon><span>' + Globalize.translate('ButtonHelp') + '</span></paper-button></a>';
2014-12-22 23:53:52 -05:00
}
html += '</div>';
$(parent).prepend(html);
},
setPageTitle: function (title) {
2015-09-21 21:05:33 -04:00
var page = $.mobile.activePage;
2015-06-28 10:45:21 -04:00
2015-09-21 21:05:33 -04:00
if (page) {
var elem = $(page)[0].querySelector('.pageTitle');
if (elem) {
elem.innerHTML = title;
}
2015-06-28 10:45:21 -04:00
}
if (title) {
document.title = title;
}
2013-06-07 13:29:33 -04:00
},
getDisplayTime: function (ticks) {
var ticksPerHour = 36000000000;
2014-05-11 01:11:53 -04:00
var ticksPerMinute = 600000000;
var ticksPerSecond = 10000000;
2013-06-07 13:29:33 -04:00
var parts = [];
var hours = ticks / ticksPerHour;
2013-12-05 22:39:44 -05:00
hours = Math.floor(hours);
2013-06-07 13:29:33 -04:00
if (hours) {
parts.push(hours);
}
ticks -= (hours * ticksPerHour);
var minutes = ticks / ticksPerMinute;
2013-12-05 22:39:44 -05:00
minutes = Math.floor(minutes);
2013-06-07 13:29:33 -04:00
ticks -= (minutes * ticksPerMinute);
if (minutes < 10 && hours) {
minutes = '0' + minutes;
}
parts.push(minutes);
var seconds = ticks / ticksPerSecond;
2014-05-11 01:11:53 -04:00
seconds = Math.floor(seconds);
2013-06-07 13:29:33 -04:00
if (seconds < 10) {
seconds = '0' + seconds;
}
parts.push(seconds);
return parts.join(':');
2013-11-07 12:27:05 -05:00
},
2013-11-28 13:27:29 -05:00
2014-04-13 13:27:13 -04:00
getSupportedRemoteCommands: function () {
// Full list
// https://github.com/MediaBrowser/MediaBrowser/blob/master/MediaBrowser.Model/Session/GeneralCommand.cs
return [
"GoHome",
"GoToSettings",
"VolumeUp",
"VolumeDown",
"Mute",
"Unmute",
"ToggleMute",
"SetVolume",
"SetAudioStreamIndex",
"SetSubtitleStreamIndex",
2014-04-27 21:57:29 -04:00
"DisplayContent",
2014-05-08 16:09:53 -04:00
"GoToSearch",
2015-07-26 17:02:23 -04:00
"DisplayMessage",
"SetRepeatMode"
2014-04-13 13:27:13 -04:00
];
2014-10-25 14:32:58 -04:00
},
2014-10-26 23:06:01 -04:00
isServerlessPage: function () {
2015-12-14 10:43:03 -05:00
var url = window.location.href.toLowerCase();
2015-05-05 19:20:23 -04:00
return url.indexOf('connectlogin.html') != -1 || url.indexOf('selectserver.html') != -1 || url.indexOf('login.html') != -1 || url.indexOf('forgotpassword.html') != -1 || url.indexOf('forgotpasswordpin.html') != -1;
2015-02-19 12:46:18 -05:00
},
capabilities: function () {
2015-05-26 11:31:50 -04:00
var caps = {
2015-05-28 19:37:43 -04:00
PlayableMediaTypes: ['Audio', 'Video'],
2015-02-19 12:46:18 -05:00
2015-05-28 19:37:43 -04:00
SupportedCommands: Dashboard.getSupportedRemoteCommands(),
2015-06-10 09:37:07 -04:00
// Need to use this rather than AppInfo.isNativeApp because the property isn't set yet at the time we call this
SupportsPersistentIdentifier: Dashboard.isRunningInCordova(),
2015-04-09 01:20:23 -04:00
SupportsMediaControl: true,
SupportedLiveMediaTypes: ['Audio', 'Video']
2015-02-19 12:46:18 -05:00
};
2015-05-26 11:31:50 -04:00
2015-12-14 10:43:03 -05:00
if (Dashboard.isRunningInCordova() && !browserInfo.safari) {
2015-05-28 19:37:43 -04:00
caps.SupportsOfflineAccess = true;
caps.SupportsSync = true;
caps.SupportsContentUploading = true;
}
2015-05-26 11:31:50 -04:00
return caps;
2015-05-02 12:34:27 -04:00
},
2013-04-01 22:14:37 -07:00
2015-05-02 12:34:27 -04:00
getDefaultImageQuality: function (imageType) {
var quality = 90;
var isBackdrop = imageType.toLowerCase() == 'backdrop';
if (isBackdrop) {
2015-05-07 10:04:10 -04:00
quality -= 10;
2015-05-02 12:34:27 -04:00
}
2015-05-06 23:11:51 -04:00
if (AppInfo.hasLowImageBandwidth) {
2014-10-24 00:54:35 -04:00
2015-05-15 11:46:20 -04:00
// The native app can handle a little bit more than safari
2015-05-28 19:37:43 -04:00
if (AppInfo.isNativeApp) {
2015-05-15 11:46:20 -04:00
2015-09-27 21:50:11 -04:00
quality -= 10;
2015-05-15 11:46:20 -04:00
} else {
2014-10-24 00:54:35 -04:00
2015-05-19 15:15:40 -04:00
quality -= 40;
2015-05-02 12:34:27 -04:00
}
2014-10-24 00:54:35 -04:00
}
2015-05-02 12:34:27 -04:00
return quality;
},
2015-05-12 09:58:03 -04:00
normalizeImageOptions: function (options) {
2015-05-11 12:32:15 -04:00
if (AppInfo.hasLowImageBandwidth) {
options.enableImageEnhancers = false;
}
2015-05-15 11:46:20 -04:00
if (AppInfo.forcedImageFormat && options.type != 'Logo') {
options.format = AppInfo.forcedImageFormat;
2015-06-26 11:53:49 -04:00
options.backgroundColor = '#1c1c1c';
2015-05-15 11:46:20 -04:00
}
2015-05-11 12:32:15 -04:00
},
2015-05-25 13:32:22 -04:00
loadExternalPlayer: function () {
2015-12-14 10:43:03 -05:00
return new Promise(function (resolve, reject) {
2015-05-25 13:32:22 -04:00
2015-12-14 10:43:03 -05:00
require(['scripts/externalplayer.js'], function () {
2015-05-25 13:32:22 -04:00
2015-12-14 10:43:03 -05:00
if (Dashboard.isRunningInCordova()) {
require(['cordova/externalplayer.js'], resolve);
} else {
resolve();
}
});
2015-05-25 13:32:22 -04:00
});
2015-06-08 17:32:20 -04:00
},
exitOnBack: function () {
return $($.mobile.activePage).is('#indexPage');
},
exit: function () {
Dashboard.logout();
2014-10-24 00:54:35 -04:00
}
2015-05-02 12:34:27 -04:00
};
2015-05-06 23:11:51 -04:00
var AppInfo = {};
2015-05-02 12:34:27 -04:00
(function () {
2014-10-24 00:54:35 -04:00
2015-05-06 23:11:51 -04:00
function isTouchDevice() {
return (('ontouchstart' in window)
|| (navigator.MaxTouchPoints > 0)
|| (navigator.msMaxTouchPoints > 0));
}
2015-05-06 23:11:51 -04:00
function setAppInfo() {
2015-05-19 15:15:40 -04:00
if (isTouchDevice()) {
2015-05-06 23:11:51 -04:00
AppInfo.isTouchPreferred = true;
}
2015-05-08 12:58:27 -04:00
var isCordova = Dashboard.isRunningInCordova();
2015-05-15 22:36:47 -04:00
AppInfo.enableDetailPageChapters = true;
AppInfo.enableDetailsMenuImages = true;
2015-05-16 15:09:02 -04:00
AppInfo.enableMovieHomeSuggestions = true;
2015-09-23 12:16:06 -04:00
AppInfo.enableNavDrawer = true;
AppInfo.enableSearchInTopMenu = true;
2015-09-24 13:08:10 -04:00
AppInfo.enableHomeFavorites = true;
AppInfo.enableNowPlayingBar = true;
2015-09-25 01:15:29 -04:00
AppInfo.enableHomeTabs = true;
2015-09-25 12:08:13 -04:00
AppInfo.enableNowPlayingPageBottomTabs = true;
2016-01-06 15:16:16 -05:00
AppInfo.enableAutoSave = browserInfo.mobile;
2015-05-16 15:09:02 -04:00
AppInfo.enableAppStorePolicy = isCordova;
2015-05-15 22:36:47 -04:00
2015-12-14 10:43:03 -05:00
var isIOS = browserInfo.ipad || browserInfo.iphone;
var isAndroid = browserInfo.android;
var isMobile = browserInfo.mobile;
2015-05-28 01:51:48 -04:00
2015-05-29 21:07:54 -04:00
if (isIOS) {
2015-05-06 23:11:51 -04:00
2015-12-14 10:43:03 -05:00
AppInfo.hasLowImageBandwidth = true;
2015-05-07 18:27:01 -04:00
2015-05-08 12:58:27 -04:00
if (isCordova) {
2015-06-20 20:49:42 -04:00
//AppInfo.enableSectionTransitions = true;
2015-09-23 12:16:06 -04:00
AppInfo.enableNavDrawer = false;
AppInfo.enableSearchInTopMenu = false;
2015-09-24 13:08:10 -04:00
AppInfo.enableHomeFavorites = false;
2015-09-25 01:15:29 -04:00
AppInfo.enableHomeTabs = false;
2015-09-25 12:08:13 -04:00
AppInfo.enableNowPlayingPageBottomTabs = false;
2015-06-04 16:27:46 -04:00
2015-09-25 22:31:13 -04:00
// Disable the now playing bar for the iphone since we already have the now playing tab at the bottom
if (navigator.userAgent.toString().toLowerCase().indexOf('iphone') != -1) {
AppInfo.enableNowPlayingBar = false;
}
2015-05-15 22:36:47 -04:00
} else {
2015-12-14 10:43:03 -05:00
AppInfo.enableDetailPageChapters = false;
AppInfo.enableDetailsMenuImages = false;
AppInfo.enableMovieHomeSuggestions = false;
2015-06-04 16:27:46 -04:00
2015-12-14 10:43:03 -05:00
AppInfo.forcedImageFormat = 'jpg';
2015-05-07 18:27:01 -04:00
}
2015-05-06 23:11:51 -04:00
}
2015-05-07 10:04:10 -04:00
2015-05-08 15:44:13 -04:00
if (!AppInfo.hasLowImageBandwidth) {
2015-05-07 10:04:10 -04:00
AppInfo.enableStudioTabs = true;
AppInfo.enableTvEpisodesTab = true;
2015-05-07 18:27:01 -04:00
}
2015-12-14 10:43:03 -05:00
AppInfo.supportsExternalPlayers = true;
2015-05-24 14:33:28 -04:00
if (isCordova) {
AppInfo.enableAppLayouts = true;
2015-12-14 10:43:03 -05:00
AppInfo.supportsExternalPlayerMenu = true;
2015-05-28 19:37:43 -04:00
AppInfo.isNativeApp = true;
2015-12-14 10:43:03 -05:00
if (isIOS) {
AppInfo.supportsExternalPlayers = false;
}
2015-05-24 14:33:28 -04:00
}
else {
2015-05-21 16:53:14 -04:00
AppInfo.enableSupporterMembership = true;
2015-05-25 13:32:22 -04:00
2015-05-29 21:07:54 -04:00
if (!isAndroid && !isIOS) {
2015-05-25 13:32:22 -04:00
AppInfo.enableAppLayouts = true;
}
2015-05-07 10:04:10 -04:00
}
2015-05-08 12:58:27 -04:00
2015-12-14 10:43:03 -05:00
// This doesn't perform well on iOS
AppInfo.enableHeadRoom = !isIOS;
2015-06-21 17:31:21 -04:00
2015-12-14 10:43:03 -05:00
AppInfo.supportsDownloading = !(AppInfo.isNativeApp && isIOS);
// This currently isn't working on android, unfortunately
AppInfo.supportsFileInput = !(AppInfo.isNativeApp && isAndroid);
2015-06-21 17:31:21 -04:00
2015-05-28 01:51:48 -04:00
AppInfo.hasPhysicalVolumeButtons = isCordova || isMobile;
2015-06-17 21:41:22 -04:00
AppInfo.enableBackButton = isIOS && (window.navigator.standalone || AppInfo.isNativeApp);
2015-06-10 00:01:14 -04:00
AppInfo.supportsSyncPathSetting = isCordova && isAndroid;
2015-08-04 14:14:16 -04:00
AppInfo.supportsUserDisplayLanguageSetting = Dashboard.isConnectMode() && !isCordova;
2015-06-11 02:27:05 -04:00
2015-07-14 12:39:34 -04:00
if (isCordova && isIOS) {
AppInfo.moreIcon = 'more-horiz';
} else {
AppInfo.moreIcon = 'more-vert';
}
}
2013-04-19 18:09:21 -04:00
2014-10-25 14:32:58 -04:00
function initializeApiClient(apiClient) {
2016-02-07 16:16:02 -05:00
if (AppInfo.enableAppStorePolicy) {
2016-02-09 12:13:50 -05:00
apiClient.getAvailablePlugins = function () {
2016-02-07 16:16:02 -05:00
return Promise.resolve([]);
};
apiClient.getInstalledPlugins = function () {
return Promise.resolve([]);
};
}
2015-06-08 17:32:20 -04:00
apiClient.getDefaultImageQuality = Dashboard.getDefaultImageQuality;
apiClient.normalizeImageOptions = Dashboard.normalizeImageOptions;
2015-05-16 15:09:02 -04:00
2015-12-23 12:46:01 -05:00
Events.off(apiClient, 'websocketmessage', Dashboard.onWebSocketMessageReceived);
Events.on(apiClient, 'websocketmessage', Dashboard.onWebSocketMessageReceived);
2015-06-29 14:45:42 -04:00
2015-12-23 12:46:01 -05:00
Events.off(apiClient, 'requestfail', Dashboard.onRequestFail);
Events.on(apiClient, 'requestfail', Dashboard.onRequestFail);
2014-10-25 14:32:58 -04:00
}
2015-05-25 13:32:22 -04:00
2015-12-30 12:02:11 -05:00
function getSyncProfile() {
return getRequirePromise(['scripts/mediaplayer']).then(function () {
return MediaPlayer.getDeviceProfile(Math.max(screen.height, screen.width));
});
}
function onApiClientCreated(e, newApiClient) {
initializeApiClient(newApiClient);
}
2015-05-24 14:33:28 -04:00
//localStorage.clear();
2015-12-23 12:46:01 -05:00
function createConnectionManager(credentialProviderFactory, capabilities) {
2015-05-01 14:37:01 -04:00
2015-06-13 10:46:59 -04:00
var credentialKey = Dashboard.isConnectMode() ? null : 'servercredentials4';
2015-12-23 12:46:01 -05:00
var credentialProvider = new credentialProviderFactory(credentialKey);
2014-10-24 00:54:35 -04:00
2015-12-30 12:02:11 -05:00
return getSyncProfile().then(function (deviceProfile) {
2015-01-25 01:34:50 -05:00
2015-12-30 12:02:11 -05:00
capabilities.DeviceProfile = deviceProfile;
2015-06-19 00:23:55 -04:00
2015-12-30 12:02:11 -05:00
window.ConnectionManager = new MediaBrowser.ConnectionManager(credentialProvider, AppInfo.appName, AppInfo.appVersion, AppInfo.deviceName, AppInfo.deviceId, capabilities, window.devicePixelRatio);
2014-05-17 00:24:10 -04:00
2015-12-30 12:02:11 -05:00
if (window.location.href.toLowerCase().indexOf('wizardstart.html') != -1) {
window.ConnectionManager.clearData();
}
2014-10-24 00:54:35 -04:00
2016-01-19 22:02:45 -05:00
console.log('binding to apiclientcreated');
2015-12-30 12:02:11 -05:00
Events.on(ConnectionManager, 'apiclientcreated', onApiClientCreated);
2015-04-01 17:56:32 -04:00
2015-12-14 10:43:03 -05:00
if (Dashboard.isConnectMode()) {
2015-04-01 17:56:32 -04:00
2015-12-14 10:43:03 -05:00
var server = ConnectionManager.getLastUsedServer();
2015-12-14 10:43:03 -05:00
if (!Dashboard.isServerlessPage()) {
2015-12-14 10:43:03 -05:00
if (server && server.UserId && server.AccessToken) {
Dashboard.showLoadingMsg();
2015-12-30 12:02:11 -05:00
return ConnectionManager.connectToServer(server).then(function (result) {
2016-02-21 17:17:38 -05:00
Dashboard.hideLoadingMsg();
2015-12-14 10:43:03 -05:00
if (result.State == MediaBrowser.ConnectionState.SignedIn) {
window.ApiClient = result.ApiClient;
}
});
}
2015-05-02 12:34:27 -04:00
}
2015-04-25 23:25:07 -04:00
2015-12-14 10:43:03 -05:00
} else {
2016-01-19 22:02:45 -05:00
console.log('loading ApiClient singleton');
2015-12-30 12:02:11 -05:00
return getRequirePromise(['apiclient']).then(function (apiClientFactory) {
2016-01-19 22:02:45 -05:00
console.log('creating ApiClient singleton');
2015-12-23 12:46:01 -05:00
var apiClient = new apiClientFactory(Dashboard.serverAddress(), AppInfo.appName, AppInfo.appVersion, AppInfo.deviceName, AppInfo.deviceId, window.devicePixelRatio);
apiClient.enableAutomaticNetworking = false;
ConnectionManager.addApiClient(apiClient);
Dashboard.importCss(apiClient.getUrl('Branding/Css'));
window.ApiClient = apiClient;
2016-01-19 22:02:45 -05:00
console.log('loaded ApiClient singleton');
2015-12-23 12:46:01 -05:00
});
2015-12-14 10:43:03 -05:00
}
});
2015-01-25 01:34:50 -05:00
}
2015-01-19 00:41:56 -05:00
2015-05-08 13:30:24 -04:00
function initFastClick() {
2015-12-14 10:43:03 -05:00
require(["fastclick"], function (FastClick) {
2015-05-08 13:30:24 -04:00
2015-07-14 12:39:34 -04:00
FastClick.attach(document.body, {
tapDelay: 0
});
2015-05-08 23:48:43 -04:00
2015-12-14 10:43:03 -05:00
function parentWithClass(elem, className) {
while (!elem.classList || !elem.classList.contains(className)) {
elem = elem.parentNode;
if (!elem) {
return null;
}
}
return elem;
}
2015-05-08 23:48:43 -04:00
// Have to work around this issue of fast click breaking the panel dismiss
2015-12-14 10:43:03 -05:00
document.body.addEventListener('touchstart', function (e) {
var tgt = parentWithClass(e.target, 'ui-panel-dismiss');
if (tgt) {
$(tgt).click();
}
2015-05-08 23:48:43 -04:00
});
2015-05-08 13:30:24 -04:00
});
2015-05-08 23:48:43 -04:00
2015-05-08 13:30:24 -04:00
}
2015-06-17 11:39:46 -04:00
function setDocumentClasses() {
2015-05-01 14:37:01 -04:00
2015-06-28 10:45:21 -04:00
var elem = document.documentElement;
2015-06-17 11:39:46 -04:00
if (AppInfo.isTouchPreferred) {
2015-06-28 10:45:21 -04:00
elem.classList.add('touch');
2015-05-08 12:58:27 -04:00
}
2015-05-06 23:11:51 -04:00
2015-05-07 10:04:10 -04:00
if (!AppInfo.enableStudioTabs) {
2015-06-28 10:45:21 -04:00
elem.classList.add('studioTabDisabled');
2015-05-07 10:04:10 -04:00
}
if (!AppInfo.enableTvEpisodesTab) {
2015-06-28 10:45:21 -04:00
elem.classList.add('tvEpisodesTabDisabled');
2015-05-07 10:04:10 -04:00
}
2015-05-21 16:53:14 -04:00
if (!AppInfo.enableSupporterMembership) {
2015-06-28 10:45:21 -04:00
elem.classList.add('supporterMembershipDisabled');
2015-05-21 16:53:14 -04:00
}
2015-05-28 19:37:43 -04:00
if (AppInfo.isNativeApp) {
2015-06-28 10:45:21 -04:00
elem.classList.add('nativeApp');
2015-06-17 11:39:46 -04:00
}
2015-09-24 13:08:10 -04:00
if (!AppInfo.enableHomeFavorites) {
elem.classList.add('homeFavoritesDisabled');
}
2015-06-17 11:39:46 -04:00
}
2015-10-13 02:31:20 -04:00
function loadTheme() {
var name = getParameterByName('theme');
if (name) {
require(['themes/' + name + '/theme']);
return;
}
var date = new Date();
2015-10-13 15:22:45 -04:00
var month = date.getMonth();
var day = date.getDate();
if (month == 9 && day >= 30) {
2015-10-13 02:31:20 -04:00
require(['themes/halloween/theme']);
return;
}
2015-12-19 23:39:51 -05:00
if (month == 11 && day >= 21 && day <= 26) {
require(['themes/holiday/theme']);
return;
}
2015-10-13 02:31:20 -04:00
}
2016-01-30 14:31:22 -05:00
function returnFirstDependency(obj) {
return obj;
}
2016-02-04 15:51:13 -05:00
function getBowerPath() {
2016-02-05 12:04:38 -05:00
2015-12-14 10:43:03 -05:00
var bowerPath = "bower_components";
// Put the version into the bower path since we can't easily put a query string param on html imports
// Emby server will handle this
2016-02-16 14:58:42 -05:00
if (Dashboard.isConnectMode() && !Dashboard.isRunningInCordova()) {
bowerPath += window.dashboardVersion;
2015-05-07 10:04:10 -04:00
}
2016-02-04 15:51:13 -05:00
return bowerPath;
}
function initRequire() {
var urlArgs = "v=" + (window.dashboardVersion || new Date().getDate());
var bowerPath = getBowerPath();
2015-12-21 12:48:31 -05:00
var apiClientBowerPath = bowerPath + "/emby-apiclient";
2015-12-26 13:35:53 -05:00
var embyWebComponentsBowerPath = bowerPath + '/emby-webcomponents';
2015-12-21 12:48:31 -05:00
2015-12-14 10:43:03 -05:00
var paths = {
velocity: bowerPath + "/velocity/velocity.min",
tvguide: 'components/tvguide/tvguide',
directorybrowser: 'components/directorybrowser/directorybrowser',
collectioneditor: 'components/collectioneditor/collectioneditor',
playlisteditor: 'components/playlisteditor/playlisteditor',
medialibrarycreator: 'components/medialibrarycreator/medialibrarycreator',
medialibraryeditor: 'components/medialibraryeditor/medialibraryeditor',
howler: bowerPath + '/howler.js/howler.min',
sortable: bowerPath + '/Sortable/Sortable.min',
isMobile: bowerPath + '/isMobile/isMobile.min',
headroom: bowerPath + '/headroom.js/dist/headroom.min',
masonry: bowerPath + '/masonry/dist/masonry.pkgd.min',
humanedate: 'components/humanedate',
chromecasthelpers: 'components/chromecasthelpers',
2016-02-22 15:29:24 -05:00
jQuery: bowerPath + '/jquery/dist/jquery.slim.min',
2016-02-27 22:39:52 -05:00
jQueryFull: bowerPath + '/jquery/dist/jquery.min',
2015-12-23 12:46:01 -05:00
fastclick: bowerPath + '/fastclick/lib/fastclick',
events: apiClientBowerPath + '/events',
credentialprovider: apiClientBowerPath + '/credentials',
apiclient: apiClientBowerPath + '/apiclient',
connectionmanagerfactory: apiClientBowerPath + '/connectionmanager',
2016-01-12 12:54:37 -05:00
visibleinviewport: embyWebComponentsBowerPath + "/visibleinviewport",
2015-12-26 13:35:53 -05:00
browserdeviceprofile: embyWebComponentsBowerPath + "/browserdeviceprofile",
browser: embyWebComponentsBowerPath + "/browser",
2015-12-30 12:02:11 -05:00
qualityoptions: embyWebComponentsBowerPath + "/qualityoptions",
2016-01-19 22:02:45 -05:00
connectservice: apiClientBowerPath + '/connectservice',
2016-01-20 20:05:14 -05:00
hammer: bowerPath + "/hammerjs/hammer.min",
2016-01-30 14:31:22 -05:00
performanceManager: embyWebComponentsBowerPath + "/performancemanager",
2016-02-04 13:19:10 -05:00
layoutManager: embyWebComponentsBowerPath + "/layoutmanager",
2016-01-30 14:31:22 -05:00
focusManager: embyWebComponentsBowerPath + "/focusmanager",
2016-01-20 20:05:14 -05:00
imageLoader: embyWebComponentsBowerPath + "/images/imagehelper"
2015-12-14 10:43:03 -05:00
};
2016-01-16 13:29:08 -05:00
if (navigator.webkitPersistentStorage) {
2016-01-20 20:05:14 -05:00
paths.imageFetcher = embyWebComponentsBowerPath + "/images/persistentimagefetcher";
2016-01-16 13:29:08 -05:00
} else if (Dashboard.isRunningInCordova()) {
2016-01-20 20:05:14 -05:00
paths.imageFetcher = 'cordova/imagestore';
2016-01-16 13:29:08 -05:00
} else {
2016-01-20 20:05:14 -05:00
paths.imageFetcher = embyWebComponentsBowerPath + "/images/basicimagefetcher";
2016-01-16 13:29:08 -05:00
}
2015-12-16 00:30:14 -05:00
paths.hlsjs = bowerPath + "/hls.js/dist/hls.min";
2015-12-14 10:43:03 -05:00
if (Dashboard.isRunningInCordova()) {
paths.sharingwidget = "cordova/sharingwidget";
paths.serverdiscovery = "cordova/serverdiscovery";
paths.wakeonlan = "cordova/wakeonlan";
2016-01-30 23:04:00 -05:00
paths.actionsheet = "cordova/actionsheet";
2015-12-14 10:43:03 -05:00
} else {
paths.sharingwidget = "components/sharingwidget";
2015-12-16 00:30:14 -05:00
paths.serverdiscovery = apiClientBowerPath + "/serverdiscovery";
paths.wakeonlan = apiClientBowerPath + "/wakeonlan";
2016-02-21 15:39:14 -05:00
define("actionsheet", [embyWebComponentsBowerPath + "/actionsheet/actionsheet"], returnFirstDependency);
2015-05-26 11:31:50 -04:00
}
2016-01-28 15:45:52 -05:00
// hack for an android test before browserInfo is loaded
if (Dashboard.isRunningInCordova() && window.MainActivity) {
paths.appStorage = "cordova/android/appstorage";
} else {
paths.appStorage = apiClientBowerPath + "/appstorage";
}
2016-02-17 21:55:15 -05:00
paths.playlistManager = "scripts/playlistmanager";
2016-02-17 23:57:19 -05:00
paths.syncDialog = "scripts/sync";
2016-02-17 21:55:15 -05:00
2015-12-14 10:43:03 -05:00
var sha1Path = bowerPath + "/cryptojslib/components/sha1-min";
var md5Path = bowerPath + "/cryptojslib/components/md5-min";
var shim = {};
2015-12-14 10:43:03 -05:00
shim[sha1Path] = {
deps: [bowerPath + "/cryptojslib/components/core-min"]
};
2014-04-13 13:27:13 -04:00
2015-12-14 10:43:03 -05:00
shim[md5Path] = {
deps: [bowerPath + "/cryptojslib/components/core-min"]
};
2015-12-14 10:43:03 -05:00
requirejs.config({
2016-01-17 02:04:56 -05:00
waitSeconds: 0,
2015-12-14 10:43:03 -05:00
map: {
'*': {
2015-12-26 13:35:53 -05:00
'css': bowerPath + '/emby-webcomponents/requirecss',
2015-12-23 15:07:03 -05:00
'html': bowerPath + '/emby-webcomponents/requirehtml'
2015-12-14 10:43:03 -05:00
}
},
urlArgs: urlArgs,
2014-04-13 13:27:13 -04:00
2015-12-14 10:43:03 -05:00
paths: paths,
shim: shim
});
2013-09-09 14:23:55 -04:00
2015-12-14 10:43:03 -05:00
define("cryptojs-sha1", [sha1Path]);
define("cryptojs-md5", [md5Path]);
2015-05-08 23:48:43 -04:00
2015-12-14 10:43:03 -05:00
// Done
define("emby-icons", ["html!" + bowerPath + "/emby-icons/emby-icons.html"]);
2014-10-25 14:32:58 -04:00
2015-12-14 10:43:03 -05:00
define("paper-spinner", ["html!" + bowerPath + "/paper-spinner/paper-spinner.html"]);
define("paper-toast", ["html!" + bowerPath + "/paper-toast/paper-toast.html"]);
define("paper-slider", ["html!" + bowerPath + "/paper-slider/paper-slider.html"]);
define("paper-tabs", ["html!" + bowerPath + "/paper-tabs/paper-tabs.html"]);
define("paper-menu", ["html!" + bowerPath + "/paper-menu/paper-menu.html"]);
2016-02-09 13:44:07 -05:00
define("paper-material", ["html!" + bowerPath + "/paper-material/paper-material.html"]);
2015-12-14 10:43:03 -05:00
define("paper-dialog", ["html!" + bowerPath + "/paper-dialog/paper-dialog.html"]);
define("paper-dialog-scrollable", ["html!" + bowerPath + "/paper-dialog-scrollable/paper-dialog-scrollable.html"]);
define("paper-button", ["html!" + bowerPath + "/paper-button/paper-button.html"]);
define("paper-icon-button", ["html!" + bowerPath + "/paper-icon-button/paper-icon-button.html"]);
define("paper-drawer-panel", ["html!" + bowerPath + "/paper-drawer-panel/paper-drawer-panel.html"]);
define("paper-radio-group", ["html!" + bowerPath + "/paper-radio-group/paper-radio-group.html"]);
define("paper-radio-button", ["html!" + bowerPath + "/paper-radio-button/paper-radio-button.html"]);
define("neon-animated-pages", ["html!" + bowerPath + "/neon-animation/neon-animated-pages.html"]);
2015-12-15 14:15:46 -05:00
define("paper-toggle-button", ["html!" + bowerPath + "/paper-toggle-button/paper-toggle-button.html"]);
2015-05-08 23:48:43 -04:00
2015-12-14 10:43:03 -05:00
define("slide-right-animation", ["html!" + bowerPath + "/neon-animation/animations/slide-right-animation.html"]);
define("slide-left-animation", ["html!" + bowerPath + "/neon-animation/animations/slide-left-animation.html"]);
define("slide-from-right-animation", ["html!" + bowerPath + "/neon-animation/animations/slide-from-right-animation.html"]);
define("slide-from-left-animation", ["html!" + bowerPath + "/neon-animation/animations/slide-from-left-animation.html"]);
define("paper-textarea", ["html!" + bowerPath + "/paper-input/paper-textarea.html"]);
define("paper-item", ["html!" + bowerPath + "/paper-item/paper-item.html"]);
define("paper-checkbox", ["html!" + bowerPath + "/paper-checkbox/paper-checkbox.html"]);
define("fade-in-animation", ["html!" + bowerPath + "/neon-animation/animations/fade-in-animation.html"]);
define("fade-out-animation", ["html!" + bowerPath + "/neon-animation/animations/fade-out-animation.html"]);
define("scale-up-animation", ["html!" + bowerPath + "/neon-animation/animations/scale-up-animation.html"]);
define("paper-fab", ["html!" + bowerPath + "/paper-fab/paper-fab.html"]);
define("paper-progress", ["html!" + bowerPath + "/paper-progress/paper-progress.html"]);
define("paper-input", ["html!" + bowerPath + "/paper-input/paper-input.html"]);
define("paper-icon-item", ["html!" + bowerPath + "/paper-item/paper-icon-item.html"]);
define("paper-item-body", ["html!" + bowerPath + "/paper-item/paper-item-body.html"]);
2016-02-07 14:47:09 -05:00
define("paper-collapse-item", ["html!" + bowerPath + "/paper-collapse-item/paper-collapse-item.html"]);
2016-02-24 12:43:06 -05:00
define("jstree", [bowerPath + "/jstree/dist/jstree", "css!thirdparty/jstree/themes/default/style.min.css"]);
2014-07-08 20:46:11 -04:00
2016-02-14 13:32:29 -05:00
define('jqm', ['thirdparty/jquerymobile-1.4.5/jquery.mobile.custom.js']);
2016-02-08 00:59:33 -05:00
define("jqmbase", ['css!thirdparty/jquerymobile-1.4.5/jquery.mobile.custom.theme.css']);
define("jqmicons", ['jqmbase', 'css!thirdparty/jquerymobile-1.4.5/jquery.mobile.custom.icons.css']);
define("jqmtable", ['jqmbase', "thirdparty/jquerymobile-1.4.5/jqm.table", 'css!thirdparty/jquerymobile-1.4.5/jqm.table.css']);
2014-07-08 20:46:11 -04:00
2016-02-08 00:59:33 -05:00
define("jqmwidget", ['jqmbase', "thirdparty/jquerymobile-1.4.5/jqm.widget"]);
2015-05-17 22:52:52 -04:00
2016-02-08 00:59:33 -05:00
define("jqmslider", ['jqmbase', "thirdparty/jquerymobile-1.4.5/jqm.slider", 'css!thirdparty/jquerymobile-1.4.5/jqm.slider.css']);
2015-05-26 11:31:50 -04:00
2016-02-08 00:59:33 -05:00
define("jqmpopup", ['jqmbase', "thirdparty/jquerymobile-1.4.5/jqm.popup", 'css!thirdparty/jquerymobile-1.4.5/jqm.popup.css']);
2015-05-28 01:51:48 -04:00
2016-02-08 00:59:33 -05:00
define("jqmlistview", ['jqmbase', 'css!thirdparty/jquerymobile-1.4.5/jqm.listview.css']);
2015-05-28 01:51:48 -04:00
2016-02-08 00:59:33 -05:00
define("jqmcontrolgroup", ['jqmbase', 'css!thirdparty/jquerymobile-1.4.5/jqm.controlgroup.css']);
2015-06-17 11:39:46 -04:00
2016-02-08 00:59:33 -05:00
define("jqmcollapsible", ['jqmbase', "jqmicons", "thirdparty/jquerymobile-1.4.5/jqm.collapsible", 'css!thirdparty/jquerymobile-1.4.5/jqm.collapsible.css']);
2015-09-24 13:08:10 -04:00
2016-02-08 00:59:33 -05:00
define("jqmcheckbox", ['jqmbase', "jqmicons", "thirdparty/jquerymobile-1.4.5/jqm.checkbox", 'css!thirdparty/jquerymobile-1.4.5/jqm.checkbox.css']);
2014-10-06 19:58:46 -04:00
2016-02-08 00:59:33 -05:00
define("jqmpanel", ['jqmbase', "thirdparty/jquerymobile-1.4.5/jqm.panel", 'css!thirdparty/jquerymobile-1.4.5/jqm.panel.css']);
2015-05-08 23:48:43 -04:00
2016-01-31 01:03:40 -05:00
define("iron-icon-set", ["html!" + bowerPath + "/iron-icon/iron-icon.html", "html!" + bowerPath + "/iron-iconset-svg/iron-iconset-svg.html"]);
define("slideshow", [embyWebComponentsBowerPath + "/slideshow/slideshow"], returnFirstDependency);
2015-09-29 12:29:06 -04:00
2015-12-14 10:43:03 -05:00
define('fetch', [bowerPath + '/fetch/fetch']);
define('webcomponentsjs', [bowerPath + '/webcomponentsjs/webcomponents-lite.min.js']);
define('native-promise-only', [bowerPath + '/native-promise-only/lib/npo.src']);
2015-10-02 02:14:04 -04:00
if (Dashboard.isRunningInCordova()) {
2015-12-14 10:43:03 -05:00
define('registrationservices', ['cordova/registrationservices']);
2015-10-02 02:14:04 -04:00
} else {
2015-12-14 10:43:03 -05:00
define('registrationservices', ['scripts/registrationservices']);
2015-10-02 02:14:04 -04:00
}
2015-12-16 00:30:14 -05:00
if (Dashboard.isRunningInCordova()) {
define("localassetmanager", ["cordova/localassetmanager"]);
define("fileupload", ["cordova/fileupload"]);
} else {
define("localassetmanager", [apiClientBowerPath + "/localassetmanager"]);
define("fileupload", [apiClientBowerPath + "/fileupload"]);
}
define("connectionmanager", [apiClientBowerPath + "/connectionmanager"]);
define("contentuploader", [apiClientBowerPath + "/sync/contentuploader"]);
define("serversync", [apiClientBowerPath + "/sync/serversync"]);
define("multiserversync", [apiClientBowerPath + "/sync/multiserversync"]);
define("offlineusersync", [apiClientBowerPath + "/sync/offlineusersync"]);
define("mediasync", [apiClientBowerPath + "/sync/mediasync"]);
2016-01-30 14:31:22 -05:00
2016-01-31 01:03:40 -05:00
define("swiper", [bowerPath + "/Swiper/dist/js/swiper.min", "css!" + bowerPath + "/Swiper/dist/css/swiper.min"], returnFirstDependency);
2016-01-30 14:31:22 -05:00
define("paperdialoghelper", [embyWebComponentsBowerPath + "/paperdialoghelper/paperdialoghelper"], returnFirstDependency);
2016-02-16 11:15:36 -05:00
define("loading", [embyWebComponentsBowerPath + "/loading/loading"], returnFirstDependency);
define("toast", [embyWebComponentsBowerPath + "/toast/toast"], returnFirstDependency);
2016-01-30 14:31:22 -05:00
// alias
define("historyManager", [], function () {
return {
pushState: function (state, title, url) {
state.navigate = false;
history.pushState(state, title, url);
jQuery.onStatePushed(state);
}
};
});
2016-01-31 01:03:40 -05:00
// mock this for now. not used in this app
define("inputManager", [], function () {
return {
on: function () {
},
off: function () {
}
};
});
define("connectionManager", [], function () {
return ConnectionManager;
});
2016-02-06 01:33:34 -05:00
define("globalize", [], function () {
return Globalize;
});
2016-02-22 13:25:45 -05:00
define('dialogText', ['globalize'], getDialogText());
2016-02-06 01:33:34 -05:00
}
function getDialogText() {
2016-02-22 13:25:45 -05:00
return function (globalize) {
2016-02-06 01:33:34 -05:00
return {
2016-02-22 13:25:45 -05:00
get: function (text) {
return globalize.translate('Button' + text);
}
2016-02-06 01:33:34 -05:00
};
};
2015-12-14 10:43:03 -05:00
}
2015-10-02 02:14:04 -04:00
2016-02-04 15:51:13 -05:00
function initRequireWithBrowser(browser) {
2016-02-05 12:04:38 -05:00
2016-02-04 15:51:13 -05:00
var bowerPath = getBowerPath();
var embyWebComponentsBowerPath = bowerPath + '/emby-webcomponents';
2016-02-22 23:20:39 -05:00
if (browser.mobile || browser.msie) {
2016-02-04 15:51:13 -05:00
define("prompt", [embyWebComponentsBowerPath + "/prompt/nativeprompt"], returnFirstDependency);
2016-02-22 13:30:38 -05:00
define("confirm", [embyWebComponentsBowerPath + "/confirm/nativeconfirm"], returnFirstDependency);
2016-02-26 15:29:27 -05:00
define("alert", [embyWebComponentsBowerPath + "/alert/nativealert"], returnFirstDependency);
2016-02-04 15:51:13 -05:00
} else {
define("prompt", [embyWebComponentsBowerPath + "/prompt/prompt"], returnFirstDependency);
2016-02-22 13:30:38 -05:00
define("confirm", [embyWebComponentsBowerPath + "/confirm/confirm"], returnFirstDependency);
2016-02-26 15:29:27 -05:00
define("alert", [embyWebComponentsBowerPath + "/alert/alert"], returnFirstDependency);
2016-02-04 15:51:13 -05:00
}
}
2015-12-14 10:43:03 -05:00
function init(hostingAppInfo) {
2015-05-08 23:48:43 -04:00
2015-12-14 10:43:03 -05:00
if (Dashboard.isRunningInCordova() && browserInfo.android) {
2015-06-20 00:48:45 -04:00
define("nativedirectorychooser", ["cordova/android/nativedirectorychooser"]);
2015-06-10 00:01:14 -04:00
}
2015-12-14 10:43:03 -05:00
if (Dashboard.isRunningInCordova() && browserInfo.android) {
2016-01-20 13:11:15 -05:00
if (MainActivity.getChromeVersion() >= 48) {
2016-02-05 11:04:31 -05:00
define("audiorenderer", ["scripts/htmlmediarenderer"]);
//define("audiorenderer", ["cordova/android/vlcplayer"]);
2016-01-20 13:11:15 -05:00
} else {
2016-02-05 11:04:31 -05:00
window.VlcAudio = true;
2016-01-20 13:11:15 -05:00
define("audiorenderer", ["cordova/android/vlcplayer"]);
}
2015-07-05 14:34:52 -04:00
define("videorenderer", ["cordova/android/vlcplayer"]);
2015-06-10 09:37:07 -04:00
}
2015-12-14 10:43:03 -05:00
else if (Dashboard.isRunningInCordova() && browserInfo.safari) {
2015-09-09 23:22:52 -04:00
define("audiorenderer", ["cordova/ios/vlcplayer"]);
define("videorenderer", ["scripts/htmlmediarenderer"]);
}
2015-06-10 09:37:07 -04:00
else {
define("audiorenderer", ["scripts/htmlmediarenderer"]);
define("videorenderer", ["scripts/htmlmediarenderer"]);
}
2015-12-14 10:43:03 -05:00
if (Dashboard.isRunningInCordova() && browserInfo.android) {
2015-08-12 17:39:02 -04:00
define("localsync", ["cordova/android/localsync"]);
}
else {
define("localsync", ["scripts/localsync"]);
}
2015-06-22 11:43:19 -04:00
define("livetvcss", [], function () {
Dashboard.importCss('css/livetv.css');
return {};
});
2015-06-23 18:13:06 -04:00
define("detailtablecss", [], function () {
Dashboard.importCss('css/detailtable.css');
return {};
});
2015-12-14 10:43:03 -05:00
define("tileitemcss", ['css!css/tileitem.css']);
2015-06-19 12:36:51 -04:00
2015-06-30 19:59:45 -04:00
define("sharingmanager", ["scripts/sharingmanager"]);
2015-07-02 01:08:05 -04:00
2015-12-14 10:43:03 -05:00
if (Dashboard.isRunningInCordova() && browserInfo.safari) {
2015-07-10 10:25:18 -04:00
define("searchmenu", ["cordova/searchmenu"]);
} else {
define("searchmenu", ["scripts/searchmenu"]);
}
2015-12-14 10:43:03 -05:00
define("buttonenabled", ["legacy/buttonenabled"]);
2015-10-13 15:22:45 -04:00
var deps = [];
2015-12-23 12:46:01 -05:00
deps.push('events');
2015-09-09 13:49:44 -04:00
2015-12-14 10:43:03 -05:00
if (!window.fetch) {
deps.push('fetch');
2015-09-09 13:49:44 -04:00
}
2015-12-14 10:43:03 -05:00
deps.push('scripts/mediacontroller');
deps.push('scripts/globalize');
deps.push('paper-drawer-panel');
2015-12-23 12:46:01 -05:00
require(deps, function (events) {
window.Events = events;
2015-09-09 13:49:44 -04:00
2015-12-14 10:43:03 -05:00
for (var i in hostingAppInfo) {
AppInfo[i] = hostingAppInfo[i];
}
initAfterDependencies();
2015-09-09 13:49:44 -04:00
});
}
2015-12-14 10:43:03 -05:00
function getRequirePromise(deps) {
return new Promise(function (resolve, reject) {
require(deps, resolve);
});
}
function initAfterDependencies() {
2015-05-19 15:15:40 -04:00
2015-07-13 17:26:11 -04:00
var drawer = document.querySelector('.mainDrawerPanel');
drawer.classList.remove('mainDrawerPanelPreInit');
drawer.forceNarrow = true;
2015-07-16 08:56:38 -04:00
var drawerWidth = screen.availWidth - 50;
// At least 240
drawerWidth = Math.max(drawerWidth, 240);
// But not exceeding 310
drawerWidth = Math.min(drawerWidth, 310);
2015-07-23 10:58:27 -04:00
2015-07-16 08:56:38 -04:00
drawer.drawerWidth = drawerWidth + "px";
2015-06-21 17:31:21 -04:00
2015-12-14 10:43:03 -05:00
if (browserInfo.safari) {
2015-07-13 17:26:11 -04:00
drawer.disableEdgeSwipe = true;
}
2015-06-21 17:31:21 -04:00
2015-07-27 14:18:10 -04:00
var deps = [];
2015-12-23 12:46:01 -05:00
deps.push('connectionmanagerfactory');
deps.push('credentialprovider');
2015-06-30 01:45:20 -04:00
2015-12-14 10:43:03 -05:00
deps.push('scripts/appsettings');
2015-12-30 12:02:11 -05:00
deps.push('scripts/extensions');
2015-06-08 17:32:20 -04:00
2015-12-23 12:46:01 -05:00
require(deps, function (connectionManagerExports, credentialProviderFactory) {
window.MediaBrowser = window.MediaBrowser || {};
for (var i in connectionManagerExports) {
MediaBrowser[i] = connectionManagerExports[i];
}
2015-05-26 11:31:50 -04:00
2015-12-14 10:43:03 -05:00
var promises = [];
deps = [];
2015-12-30 12:02:11 -05:00
deps.push('scripts/mediaplayer');
2015-12-14 10:43:03 -05:00
deps.push('emby-icons');
deps.push('paper-icon-button');
deps.push('paper-button');
2016-02-14 15:34:54 -05:00
deps.push('jQuery');
2015-12-14 10:43:03 -05:00
promises.push(getRequirePromise(deps));
2015-07-27 14:18:10 -04:00
2015-12-14 10:43:03 -05:00
promises.push(Globalize.ensure());
2015-12-30 12:02:11 -05:00
promises.push(createConnectionManager(credentialProviderFactory, Dashboard.capabilities()));
2015-06-26 23:27:38 -04:00
2015-12-14 10:43:03 -05:00
Promise.all(promises).then(function () {
2016-01-19 22:02:45 -05:00
console.log('initAfterDependencies promises resolved');
2015-12-14 10:43:03 -05:00
MediaController.init();
document.title = Globalize.translateDocument(document.title, 'html');
2015-07-27 15:16:30 -04:00
2015-07-27 22:05:06 -04:00
var mainDrawerPanelContent = document.querySelector('.mainDrawerPanelContent');
if (mainDrawerPanelContent) {
2015-09-01 22:56:19 -04:00
2015-07-27 22:05:06 -04:00
var newHtml = mainDrawerPanelContent.innerHTML.substring(4);
newHtml = newHtml.substring(0, newHtml.length - 3);
2015-09-01 00:15:10 -04:00
var srch = 'data-require=';
var index = newHtml.indexOf(srch);
2015-09-01 22:56:19 -04:00
var depends;
2015-09-01 00:15:10 -04:00
if (index != -1) {
var requireAttribute = newHtml.substring(index + srch.length + 1);
requireAttribute = requireAttribute.substring(0, requireAttribute.indexOf('"'));
2015-09-01 22:56:19 -04:00
depends = requireAttribute.split(',');
}
2015-09-01 00:15:10 -04:00
2015-09-01 22:56:19 -04:00
depends = depends || [];
2015-09-01 00:15:10 -04:00
2015-09-01 22:56:19 -04:00
if (newHtml.indexOf('type-interior') != -1) {
2016-02-07 14:47:09 -05:00
addLegacyDependencies(depends, window.location.href);
2015-09-01 00:15:10 -04:00
}
2015-09-01 22:56:19 -04:00
require(depends, function () {
2016-02-14 15:34:54 -05:00
// TODO: This needs to be deprecated, but it's used heavily
$.fn.checked = function (value) {
if (value === true || value === false) {
// Set the value of the checkbox
return $(this).each(function () {
this.checked = value;
});
} else {
// Return check state
return this.length && this[0].checked;
}
};
2015-09-01 22:56:19 -04:00
// Don't like having to use jQuery here, but it takes care of making sure that embedded script executes
$(mainDrawerPanelContent).html(Globalize.translateDocument(newHtml, 'html'));
2015-12-14 10:43:03 -05:00
onAppReady();
2015-09-01 22:56:19 -04:00
});
return;
2015-07-27 15:16:30 -04:00
}
2015-12-14 10:43:03 -05:00
onAppReady();
2015-07-13 17:26:11 -04:00
});
2015-07-27 14:18:10 -04:00
});
2015-05-19 15:15:40 -04:00
}
2015-12-14 10:43:03 -05:00
function onAppReady() {
2015-09-10 14:28:22 -04:00
2016-01-19 22:02:45 -05:00
console.log('Begin onAppReady');
2015-09-23 12:16:06 -04:00
var deps = [];
2016-01-20 20:05:14 -05:00
deps.push('imageLoader');
2015-12-14 10:43:03 -05:00
if (!(AppInfo.isNativeApp && browserInfo.android)) {
document.documentElement.classList.add('minimumSizeTabs');
}
// Do these now to prevent a flash of content
if (AppInfo.isNativeApp && browserInfo.android) {
deps.push('css!devices/android/android.css');
} else if (AppInfo.isNativeApp && browserInfo.safari) {
deps.push('css!devices/ios/ios.css');
2016-02-17 21:55:15 -05:00
} else if (AppInfo.isNativeApp && browserInfo.edge) {
deps.push('css!devices/windowsphone/wp.css');
2015-12-14 10:43:03 -05:00
} else if (!browserInfo.android) {
deps.push('css!devices/android/android.css');
}
2015-10-05 22:50:20 -04:00
2015-12-14 10:43:03 -05:00
loadTheme();
if (browserInfo.safari && browserInfo.mobile) {
initFastClick();
}
if (Dashboard.isRunningInCordova()) {
deps.push('registrationservices');
deps.push('cordova/back');
2015-10-05 22:50:20 -04:00
2015-12-14 10:43:03 -05:00
if (browserInfo.android) {
deps.push('cordova/android/androidcredentials');
2016-02-19 21:45:12 -05:00
deps.push('cordova/links');
2015-12-14 10:43:03 -05:00
}
2015-09-21 21:05:33 -04:00
}
2015-12-14 10:43:03 -05:00
if (browserInfo.msie) {
deps.push('devices/ie/ie');
2015-09-24 15:30:25 -04:00
}
2015-09-23 12:16:06 -04:00
2015-12-14 10:43:03 -05:00
deps.push('scripts/search');
deps.push('scripts/librarylist');
deps.push('scripts/backdrops');
deps.push('scripts/librarymenu');
2016-01-19 22:02:45 -05:00
deps.push('scripts/librarybrowser');
2016-02-14 15:34:54 -05:00
deps.push('jqm');
2015-12-14 10:43:03 -05:00
deps.push('css!css/card.css');
2016-01-20 20:05:14 -05:00
require(deps, function (imageLoader) {
imageLoader.enableFade = browserInfo.animate && !browserInfo.mobile;
window.ImageLoader = imageLoader;
2015-09-23 12:16:06 -04:00
2015-12-14 10:43:03 -05:00
$.mobile.filterHtml = Dashboard.filterHtml;
2015-09-23 12:16:06 -04:00
$.mobile.initializePage();
2015-12-14 10:43:03 -05:00
var postInitDependencies = [];
postInitDependencies.push('scripts/thememediaplayer');
postInitDependencies.push('scripts/remotecontrol');
postInitDependencies.push('css!css/notifications.css');
postInitDependencies.push('css!css/chromecast.css');
if (Dashboard.isRunningInCordova()) {
if (browserInfo.android) {
postInitDependencies.push('cordova/android/mediasession');
2016-01-08 23:28:09 -05:00
postInitDependencies.push('cordova/android/chromecast');
2015-12-14 10:43:03 -05:00
} else {
postInitDependencies.push('cordova/volume');
}
if (browserInfo.safari) {
2016-01-08 23:28:09 -05:00
postInitDependencies.push('cordova/connectsdk/connectsdk');
2015-12-14 10:43:03 -05:00
postInitDependencies.push('cordova/ios/orientation');
if (Dashboard.capabilities().SupportsSync) {
postInitDependencies.push('cordova/ios/backgroundfetch');
}
}
} else if (browserInfo.chrome) {
postInitDependencies.push('scripts/chromecast');
}
if (AppInfo.enableNowPlayingBar) {
postInitDependencies.push('scripts/nowplayingbar');
}
if (AppInfo.isNativeApp && browserInfo.safari) {
postInitDependencies.push('cordova/ios/tabbar');
}
2015-12-25 23:08:25 -05:00
postInitDependencies.push('components/remotecontrolautoplay');
2015-12-14 10:43:03 -05:00
require(postInitDependencies);
2015-09-23 12:16:06 -04:00
});
2015-09-01 00:15:10 -04:00
}
2015-12-14 10:43:03 -05:00
function getCordovaHostingAppInfo() {
return new Promise(function (resolve, reject) {
document.addEventListener("deviceready", function () {
2015-05-23 16:44:15 -04:00
2015-12-14 10:43:03 -05:00
cordova.getAppVersion.getVersionNumber(function (appVersion) {
2015-05-19 15:15:40 -04:00
2015-12-14 10:43:03 -05:00
var name = browserInfo.android ? "Emby for Android Mobile" : (browserInfo.safari ? "Emby for iOS" : "Emby Mobile");
2015-05-26 11:31:50 -04:00
2015-12-14 10:43:03 -05:00
// Remove special characters
var cleanDeviceName = device.model.replace(/[^\w\s]/gi, '');
2016-02-05 12:04:38 -05:00
var deviceId = null;
if (window.MainActivity) {
deviceId = MainActivity.getLegacyDeviceId();
}
2015-12-14 10:43:03 -05:00
resolve({
2016-02-05 12:04:38 -05:00
deviceId: deviceId || device.uuid,
2015-12-14 10:43:03 -05:00
deviceName: cleanDeviceName,
appName: name,
appVersion: appVersion
});
2015-08-12 17:39:02 -04:00
2015-12-14 10:43:03 -05:00
});
2015-10-01 12:28:24 -04:00
2015-12-14 10:43:03 -05:00
}, false);
2015-09-19 22:06:56 -04:00
});
2015-05-19 15:15:40 -04:00
}
2015-12-14 10:43:03 -05:00
function getWebHostingAppInfo() {
2015-05-02 12:34:27 -04:00
2015-12-14 10:43:03 -05:00
return new Promise(function (resolve, reject) {
2015-04-30 23:00:29 -04:00
2015-12-14 10:43:03 -05:00
var deviceName;
2015-05-19 15:15:40 -04:00
2015-12-14 10:43:03 -05:00
if (browserInfo.chrome) {
deviceName = "Chrome";
} else if (browserInfo.edge) {
deviceName = "Edge";
2016-01-19 10:25:34 -05:00
} else if (browserInfo.firefox) {
2015-12-14 10:43:03 -05:00
deviceName = "Firefox";
} else if (browserInfo.msie) {
deviceName = "Internet Explorer";
} else {
deviceName = "Web Browser";
}
2015-05-15 11:46:20 -04:00
2015-12-14 10:43:03 -05:00
if (browserInfo.version) {
deviceName += " " + browserInfo.version;
}
2015-05-01 14:37:01 -04:00
2015-12-14 10:43:03 -05:00
if (browserInfo.ipad) {
deviceName += " Ipad";
} else if (browserInfo.iphone) {
deviceName += " Iphone";
} else if (browserInfo.android) {
deviceName += " Android";
}
2015-05-01 14:37:01 -04:00
2015-12-14 10:43:03 -05:00
function onDeviceAdAcquired(id) {
2015-05-02 12:34:27 -04:00
2015-12-14 10:43:03 -05:00
resolve({
deviceId: id,
deviceName: deviceName,
appName: "Emby Web Client",
appVersion: window.dashboardVersion
});
}
2016-02-11 13:29:32 -05:00
var deviceIdKey = '_deviceId1';
var deviceId = appStorage.getItem(deviceIdKey);
2015-12-14 10:43:03 -05:00
if (deviceId) {
onDeviceAdAcquired(deviceId);
} else {
require(['cryptojs-sha1'], function () {
var keys = [];
keys.push(navigator.userAgent);
keys.push((navigator.cpuClass || ""));
2016-01-16 13:29:08 -05:00
keys.push(new Date().getTime());
2015-12-14 10:43:03 -05:00
var randomId = CryptoJS.SHA1(keys.join('|')).toString();
2016-02-11 13:29:32 -05:00
appStorage.setItem(deviceIdKey, randomId);
2015-12-14 10:43:03 -05:00
onDeviceAdAcquired(randomId);
});
}
});
}
function getHostingAppInfo() {
2015-06-17 11:39:46 -04:00
2015-07-13 17:26:11 -04:00
if (Dashboard.isRunningInCordova()) {
2015-12-14 10:43:03 -05:00
return getCordovaHostingAppInfo();
}
return getWebHostingAppInfo();
}
initRequire();
2015-12-30 12:02:11 -05:00
function onWebComponentsReady() {
2015-12-14 10:43:03 -05:00
2015-12-30 12:02:11 -05:00
var initialDependencies = [];
2015-12-14 10:43:03 -05:00
2015-12-30 12:02:11 -05:00
initialDependencies.push('browser');
2016-01-28 15:45:52 -05:00
initialDependencies.push('appStorage');
2015-12-14 10:43:03 -05:00
2015-12-30 12:02:11 -05:00
if (!window.Promise) {
initialDependencies.push('native-promise-only');
}
2015-12-14 10:43:03 -05:00
2016-01-28 15:45:52 -05:00
require(initialDependencies, function (browser, appStorage) {
2015-12-14 10:43:03 -05:00
2016-02-04 15:51:13 -05:00
initRequireWithBrowser(browser);
2015-12-30 12:02:11 -05:00
window.browserInfo = browser;
2016-01-28 15:45:52 -05:00
window.appStorage = appStorage;
2015-12-30 12:02:11 -05:00
setAppInfo();
setDocumentClasses();
2015-12-14 10:43:03 -05:00
2015-12-30 12:02:11 -05:00
getHostingAppInfo().then(function (hostingAppInfo) {
init(hostingAppInfo);
2015-12-14 10:43:03 -05:00
});
2015-12-30 12:02:11 -05:00
});
}
2015-12-14 10:43:03 -05:00
2015-12-30 12:02:11 -05:00
if ('registerElement' in document && 'content' in document.createElement('template')) {
// Native web components support
onWebComponentsReady();
} else {
document.addEventListener('WebComponentsReady', onWebComponentsReady);
require(['webcomponentsjs']);
}
2015-05-13 00:55:19 -04:00
2015-04-30 23:00:29 -04:00
})();
2016-02-07 14:47:09 -05:00
function addLegacyDependencies(depends, url) {
var isPluginpage = url.toLowerCase().indexOf('/configurationpage?') != -1;
if (isPluginpage) {
depends.push('jqmpopup');
depends.push('jqmcollapsible');
2016-02-11 13:29:32 -05:00
depends.push('jqmcheckbox');
2016-02-22 14:31:28 -05:00
depends.push('legacy/dashboard');
2016-02-27 22:39:52 -05:00
depends.push('jQueryFull');
2016-02-07 14:47:09 -05:00
}
depends.push('jqmcontrolgroup');
depends.push('jqmlistview');
depends.push('scripts/notifications');
}
2015-09-06 15:09:36 -04:00
function pageClassOn(eventName, className, fn) {
2015-12-14 10:43:03 -05:00
document.addEventListener(eventName, function (e) {
2015-09-06 15:09:36 -04:00
var target = e.target;
if (target.classList.contains(className)) {
fn.call(target, e);
}
});
}
function pageIdOn(eventName, id, fn) {
2015-12-14 10:43:03 -05:00
document.addEventListener(eventName, function (e) {
2015-09-06 15:09:36 -04:00
var target = e.target;
if (target.id == id) {
fn.call(target, e);
}
});
}
pageClassOn('pagecreate', "page", function () {
2015-01-18 00:45:10 -05:00
2015-12-14 10:43:03 -05:00
var page = this;
2015-01-18 00:45:10 -05:00
2015-12-14 10:43:03 -05:00
var current = page.getAttribute('data-theme');
2015-09-04 16:32:20 -04:00
2015-05-13 23:24:25 -04:00
if (!current) {
2015-01-18 23:29:57 -05:00
2015-05-13 23:24:25 -04:00
var newTheme;
2015-01-18 00:45:10 -05:00
2015-12-14 10:43:03 -05:00
if (page.classList.contains('libraryPage')) {
2015-05-13 23:24:25 -04:00
newTheme = 'b';
} else {
newTheme = 'a';
}
2015-01-18 00:45:10 -05:00
2015-12-14 10:43:03 -05:00
page.setAttribute("data-theme", newTheme);
2015-05-13 23:24:25 -04:00
}
2015-09-06 15:09:36 -04:00
});
pageClassOn('pageshow', "page", function () {
2015-09-04 16:32:20 -04:00
var page = this;
var currentTheme = page.classList.contains('ui-page-theme-a') ? 'a' : 'b';
2015-09-04 12:20:54 -04:00
var docElem = document.documentElement;
2015-09-04 16:32:20 -04:00
if (currentTheme == 'a') {
2015-09-04 12:20:54 -04:00
docElem.classList.add('background-theme-a');
docElem.classList.remove('background-theme-b');
2015-09-19 22:06:56 -04:00
page.classList.add('ui-body-a');
page.classList.remove('ui-body-b');
2015-09-04 12:20:54 -04:00
} else {
docElem.classList.add('background-theme-b');
docElem.classList.remove('background-theme-a');
2015-09-19 22:06:56 -04:00
page.classList.add('ui-body-b');
page.classList.remove('ui-body-a');
2015-09-04 12:20:54 -04:00
}
2015-12-14 10:43:03 -05:00
if (currentTheme != 'a' && !browserInfo.mobile) {
2016-01-30 23:04:00 -05:00
document.documentElement.classList.add('darkScrollbars');
2015-05-13 23:24:25 -04:00
} else {
2016-01-30 23:04:00 -05:00
document.documentElement.classList.remove('darkScrollbars');
2015-01-18 00:45:10 -05:00
}
2015-09-01 10:01:59 -04:00
Dashboard.ensurePageTitle(page);
2015-05-18 18:23:03 -04:00
var apiClient = window.ApiClient;
2014-10-25 14:32:58 -04:00
2015-05-20 12:28:55 -04:00
if (apiClient && apiClient.accessToken() && Dashboard.getCurrentUserId()) {
2015-06-28 10:45:21 -04:00
var isSettingsPage = page.classList.contains('type-interior');
2015-05-31 14:22:51 -04:00
if (isSettingsPage) {
2015-09-05 12:58:27 -04:00
2015-05-31 14:22:51 -04:00
Dashboard.ensureToolsMenu(page);
2013-05-10 08:18:07 -04:00
2015-12-14 10:43:03 -05:00
Dashboard.getCurrentUser().then(function (user) {
2014-10-25 14:32:58 -04:00
2015-05-31 14:22:51 -04:00
if (!user.Policy.IsAdministrator) {
Dashboard.logout();
}
});
}
}
2013-04-25 23:31:10 -04:00
2014-04-24 13:30:59 -04:00
else {
2015-05-05 11:24:47 -04:00
var isConnectMode = Dashboard.isConnectMode();
if (isConnectMode) {
2015-05-06 23:11:51 -04:00
2015-05-05 11:24:47 -04:00
if (!Dashboard.isServerlessPage()) {
2015-05-25 13:32:22 -04:00
Dashboard.logout();
2015-05-05 11:24:47 -04:00
return;
}
}
2015-05-06 23:11:51 -04:00
2015-11-29 13:37:31 -05:00
if (!isConnectMode && this.id !== "loginPage" && !page.classList.contains('forgotPasswordPage') && !page.classList.contains('forgotPasswordPinPage') && !page.classList.contains('wizardPage') && this.id !== 'publicSharedItemPage') {
2014-10-21 08:42:02 -04:00
2015-12-23 12:46:01 -05:00
console.log('Not logged into server. Redirecting to login.');
2015-05-25 13:32:22 -04:00
Dashboard.logout();
2014-04-24 13:30:59 -04:00
return;
}
}
2015-05-25 13:32:22 -04:00
Dashboard.ensureHeader(page);
2014-10-25 14:32:58 -04:00
if (apiClient && !apiClient.isWebSocketOpen()) {
2013-07-16 12:03:28 -04:00
Dashboard.refreshSystemInfoFromServer();
}
2015-09-06 15:09:36 -04:00
});
2015-12-14 10:43:03 -05:00
window.addEventListener("beforeunload", function () {
var apiClient = window.ApiClient;
// Close the connection gracefully when possible
if (apiClient && apiClient.isWebSocketOpen()) {
var localActivePlayers = MediaController.getPlayers().filter(function (p) {
return p.isLocalPlayer && p.isPlaying();
});
if (!localActivePlayers.length) {
2015-12-23 12:46:01 -05:00
console.log('Sending close web socket command');
2015-12-14 10:43:03 -05:00
apiClient.closeWebSocket();
}
}
});