mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
create localStorage abstraction
This commit is contained in:
parent
ecba850f43
commit
c5a40e9616
19 changed files with 138 additions and 103 deletions
Binary file not shown.
Before Width: | Height: | Size: 1.5 KiB |
Binary file not shown.
Before Width: | Height: | Size: 1.3 KiB |
Binary file not shown.
Before Width: | Height: | Size: 1.2 KiB |
Binary file not shown.
Before Width: | Height: | Size: 789 B |
Binary file not shown.
Before Width: | Height: | Size: 916 B |
|
@ -22,7 +22,7 @@
|
|||
|
||||
var deferred = $.Deferred();
|
||||
|
||||
var data = sessionStorage.getItem(key);
|
||||
var data = sessionStore.getItem(key);
|
||||
|
||||
if (data) {
|
||||
|
||||
|
@ -51,7 +51,7 @@
|
|||
};
|
||||
});
|
||||
|
||||
sessionStorage.setItem(key, JSON.stringify(images));
|
||||
sessionStore.setItem(key, JSON.stringify(images));
|
||||
deferred.resolveWith(null, [images]);
|
||||
});
|
||||
}
|
||||
|
@ -101,7 +101,7 @@
|
|||
|
||||
var userId = Dashboard.getCurrentUserId();
|
||||
|
||||
var val = LocalSettings.val('enableBackdrops', userId);
|
||||
var val = store.getItem('enableBackdrops', userId);
|
||||
|
||||
// For bandwidth
|
||||
return val == '1' || (val != '0' && !$.browser.mobile);
|
||||
|
|
|
@ -1,25 +1,4 @@
|
|||
function IsStorageEnabled(skipRetry) {
|
||||
|
||||
if (!window.localStorage) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
window.localStorage.setItem("__test", "data");
|
||||
} catch (err) {
|
||||
|
||||
if (!skipRetry) {
|
||||
if ((err.name).toUpperCase().indexOf('EXCEEDED') != -1) {
|
||||
window.localStorage.clear();
|
||||
return IsStorageEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function htmlEncode(value) {
|
||||
function htmlEncode(value) {
|
||||
//create a in-memory div, set it's inner text(which jQuery automatically encodes)
|
||||
//then grab the encoded contents back out. The div never exists on the page.
|
||||
return $('<div/>').text(value).html();
|
||||
|
@ -540,3 +519,43 @@ function ticks_to_human(str) {
|
|||
};
|
||||
|
||||
})(window);
|
||||
|
||||
(function (window) {
|
||||
|
||||
function myStore(defaultObject) {
|
||||
|
||||
var self = this;
|
||||
self.localData = {};
|
||||
|
||||
self.setItem = function (name, value) {
|
||||
|
||||
if (defaultObject) {
|
||||
defaultObject.setItem(name, value);
|
||||
} else {
|
||||
self.localData[name] = value;
|
||||
}
|
||||
};
|
||||
|
||||
self.getItem = function (name) {
|
||||
|
||||
if (defaultObject) {
|
||||
return defaultObject.getItem(name);
|
||||
}
|
||||
|
||||
return self.localData[name];
|
||||
};
|
||||
|
||||
self.removeItem = function (name) {
|
||||
|
||||
if (defaultObject) {
|
||||
defaultObject.removeItem(name);
|
||||
} else {
|
||||
self.localData[name] = null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
window.store = new myStore(window.localStorage);
|
||||
window.sessionStore = new myStore(window.sessionStorage);
|
||||
|
||||
})(window);
|
|
@ -1,4 +1,4 @@
|
|||
var LibraryBrowser = (function (window, document, $, screen, localStorage) {
|
||||
var LibraryBrowser = (function (window, document, $, screen, store) {
|
||||
|
||||
$(function () {
|
||||
$("body").on("create", function () {
|
||||
|
@ -12,7 +12,7 @@
|
|||
|
||||
getDefaultPageSize: function () {
|
||||
|
||||
var saved = localStorage.getItem('pagesize_');
|
||||
var saved = store.getItem('pagesize_');
|
||||
|
||||
if (saved) {
|
||||
return parseInt(saved);
|
||||
|
@ -32,7 +32,7 @@
|
|||
|
||||
loadSavedQueryValues: function (key, query) {
|
||||
|
||||
var values = localStorage.getItem(key + '_' + Dashboard.getCurrentUserId());
|
||||
var values = store.getItem(key + '_' + Dashboard.getCurrentUserId());
|
||||
|
||||
if (values) {
|
||||
|
||||
|
@ -56,7 +56,7 @@
|
|||
}
|
||||
|
||||
try {
|
||||
localStorage.setItem(key + '_' + Dashboard.getCurrentUserId(), JSON.stringify(values));
|
||||
store.setItem(key + '_' + Dashboard.getCurrentUserId(), JSON.stringify(values));
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
|
@ -65,7 +65,7 @@
|
|||
saveViewSetting: function (key, value) {
|
||||
|
||||
try {
|
||||
localStorage.setItem(key + '_' + Dashboard.getCurrentUserId() + '_view', value);
|
||||
store.setItem(key + '_' + Dashboard.getCurrentUserId() + '_view', value);
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
|
@ -74,7 +74,7 @@
|
|||
getSavedViewSetting: function (key) {
|
||||
|
||||
var deferred = $.Deferred();
|
||||
var val = localStorage.getItem(key + '_' + Dashboard.getCurrentUserId() + '_view');
|
||||
var val = store.getItem(key + '_' + Dashboard.getCurrentUserId() + '_view');
|
||||
|
||||
deferred.resolveWith(null, [val]);
|
||||
return deferred.promise();
|
||||
|
@ -325,7 +325,7 @@
|
|||
html += '<li><a href="#" onclick="MediaController.play({ids:[\'' + itemId + '\'],startPositionTicks:' + resumePositionTicks + '});LibraryBrowser.closePlayMenu();">Resume</a></li>';
|
||||
}
|
||||
|
||||
if (MediaController.canQueueMediaType(mediaType)) {
|
||||
if (MediaController.canQueueMediaType(mediaType, itemType)) {
|
||||
html += '<li><a href="#" onclick="MediaController.queue(\'' + itemId + '\');LibraryBrowser.closePlayMenu();">Queue</a></li>';
|
||||
}
|
||||
|
||||
|
@ -1507,7 +1507,7 @@
|
|||
|
||||
if (query.Limit && updatePageSizeSetting !== false) {
|
||||
try {
|
||||
localStorage.setItem('pagesize_', query.Limit);
|
||||
store.setItem('pagesize_', query.Limit);
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
|
@ -2279,4 +2279,4 @@
|
|||
|
||||
};
|
||||
|
||||
})(window, document, jQuery, screen, localStorage);
|
||||
})(window, document, jQuery, screen, window.store);
|
|
@ -261,7 +261,7 @@
|
|||
html += '<li data-icon="video"><a href="#" class="btnPlayTrailer" data-itemid="' + itemId + '">' + Globalize.translate('ButtonPlayTrailer') + '</a></li>';
|
||||
}
|
||||
|
||||
if (MediaController.canQueueMediaType(item.MediaType)) {
|
||||
if (MediaController.canQueueMediaType(item.MediaType, item.Type)) {
|
||||
html += '<li data-icon="plus"><a href="#" class="btnQueue" data-itemid="' + itemId + '">' + Globalize.translate('ButtonQueue') + '</a></li>';
|
||||
}
|
||||
|
||||
|
|
|
@ -223,7 +223,7 @@
|
|||
|
||||
function getTopParentId() {
|
||||
|
||||
return getParameterByName('topParentId') || sessionStorage.getItem('topParentId') || null;
|
||||
return getParameterByName('topParentId') || sessionStore.getItem('topParentId') || null;
|
||||
}
|
||||
|
||||
window.LibraryMenu = {
|
||||
|
@ -263,7 +263,7 @@
|
|||
'' :
|
||||
getTopParentId() || '';
|
||||
|
||||
sessionStorage.setItem('topParentId', id);
|
||||
sessionStore.setItem('topParentId', id);
|
||||
|
||||
$('.lnkMediaFolder').each(function () {
|
||||
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
(function ($, window, document) {
|
||||
|
||||
function get(key, userId) {
|
||||
|
||||
return localStorage.getItem(key + '-' + userId);
|
||||
}
|
||||
|
||||
function set(key, userId, value) {
|
||||
|
||||
localStorage.setItem(key + '-' + userId, value);
|
||||
}
|
||||
|
||||
function localSettings() {
|
||||
|
||||
var self = this;
|
||||
|
||||
self.val = function (key, userId, value) {
|
||||
|
||||
if (arguments.length < 3) {
|
||||
|
||||
return get(key, userId);
|
||||
}
|
||||
|
||||
set(key, userId, value);
|
||||
};
|
||||
}
|
||||
|
||||
window.LocalSettings = new localSettings();
|
||||
|
||||
})(jQuery, window, document);
|
|
@ -203,7 +203,11 @@
|
|||
return self.getPlayerInfo().playableMediaTypes.indexOf(item.MediaType) != -1;
|
||||
};
|
||||
|
||||
self.canQueueMediaType = function (mediaType) {
|
||||
self.canQueueMediaType = function (mediaType, itemType) {
|
||||
|
||||
if (itemType == 'MusicAlbum' || itemType == 'MusicArtist' || itemType == 'MusicGenre') {
|
||||
mediaType = 'Audio';
|
||||
}
|
||||
|
||||
return currentPlayer.canQueueMediaType(mediaType);
|
||||
};
|
||||
|
|
|
@ -398,7 +398,7 @@
|
|||
var maxWidth = parseInt(this.getAttribute('data-maxwidth'));
|
||||
var bitrate = parseInt(this.getAttribute('data-bitrate'));
|
||||
|
||||
localStorage.setItem('preferredVideoBitrate', bitrate);
|
||||
store.setItem('preferredVideoBitrate', bitrate);
|
||||
|
||||
self.changeStream(self.getCurrentTicks(), {
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
(function (document, setTimeout, clearTimeout, screen, localStorage, $, setInterval, window) {
|
||||
(function (document, setTimeout, clearTimeout, screen, store, $, setInterval, window) {
|
||||
|
||||
function mediaPlayer() {
|
||||
|
||||
|
@ -116,11 +116,13 @@
|
|||
|
||||
var currentSrc = element.currentSrc;
|
||||
|
||||
var transcodingExtension = self.getTranscodingExtension();
|
||||
var transcodingExtension;
|
||||
var isStatic;
|
||||
|
||||
if (self.currentItem.MediaType == "Video") {
|
||||
|
||||
transcodingExtension = self.getTranscodingExtension();
|
||||
|
||||
if (params.AudioStreamIndex != null) {
|
||||
currentSrc = replaceQueryString(currentSrc, 'AudioStreamIndex', params.AudioStreamIndex);
|
||||
}
|
||||
|
@ -155,6 +157,8 @@
|
|||
currentSrc = replaceQueryString(currentSrc, 'Static', finalParams.isStatic);
|
||||
currentSrc = replaceQueryString(currentSrc, 'AudioCodec', finalParams.audioCodec);
|
||||
isStatic = finalParams.isStatic;
|
||||
} else {
|
||||
transcodingExtension = '.mp3';
|
||||
}
|
||||
|
||||
var isSeekableMedia = self.currentMediaSource.RunTimeTicks;
|
||||
|
@ -436,7 +440,7 @@
|
|||
};
|
||||
|
||||
self.getBitrateSetting = function () {
|
||||
return parseInt(localStorage.getItem('preferredVideoBitrate') || '') || 1500000;
|
||||
return parseInt(store.getItem('preferredVideoBitrate') || '') || 1500000;
|
||||
};
|
||||
|
||||
function getOptimalMediaSource(mediaType, versions) {
|
||||
|
@ -768,13 +772,13 @@
|
|||
self.saveVolume = function (val) {
|
||||
|
||||
if (val) {
|
||||
localStorage.setItem("volume", val);
|
||||
store.setItem("volume", val);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
self.getSavedVolume = function () {
|
||||
return localStorage.getItem("volume") || 0.5;
|
||||
return store.getItem("volume") || 0.5;
|
||||
};
|
||||
|
||||
self.shuffle = function (id) {
|
||||
|
@ -1291,4 +1295,4 @@
|
|||
window.MediaController.setActivePlayer(window.MediaPlayer);
|
||||
|
||||
|
||||
})(document, setTimeout, clearTimeout, screen, localStorage, $, setInterval, window);
|
||||
})(document, setTimeout, clearTimeout, screen, window.store, $, setInterval, window);
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
function loadForm(page, userId, displayPreferences) {
|
||||
|
||||
$('#selectThemeSong', page).val(LocalSettings.val('enableThemeSongs', userId) || '').selectmenu("refresh");
|
||||
$('#selectBackdrop', page).val(LocalSettings.val('enableBackdrops', userId) || '').selectmenu("refresh");
|
||||
$('#selectThemeSong', page).val(store.getItem('enableThemeSongs', userId) || '').selectmenu("refresh");
|
||||
$('#selectBackdrop', page).val(store.getItem('enableBackdrops', userId) || '').selectmenu("refresh");
|
||||
|
||||
$('#selectHomeSection1', page).val(displayPreferences.CustomPrefs.home0 || '').selectmenu("refresh");
|
||||
$('#selectHomeSection2', page).val(displayPreferences.CustomPrefs.home1 || '').selectmenu("refresh");
|
||||
|
@ -15,8 +15,8 @@
|
|||
|
||||
function saveUser(page, userId, displayPreferences) {
|
||||
|
||||
LocalSettings.val('enableThemeSongs', userId, $('#selectThemeSong', page).val());
|
||||
LocalSettings.val('enableBackdrops', userId, $('#selectBackdrop', page).val());
|
||||
store.setItem('enableThemeSongs', userId, $('#selectThemeSong', page).val());
|
||||
store.setItem('enableBackdrops', userId, $('#selectBackdrop', page).val());
|
||||
|
||||
displayPreferences.CustomPrefs.home0 = $('#selectHomeSection1', page).val();
|
||||
displayPreferences.CustomPrefs.home1 = $('#selectHomeSection2', page).val();
|
||||
|
|
|
@ -95,17 +95,14 @@ var Dashboard = {
|
|||
|
||||
getAccessToken: function () {
|
||||
|
||||
return localStorage.getItem('token');
|
||||
return store.getItem('token');
|
||||
},
|
||||
|
||||
getCurrentUserId: function () {
|
||||
|
||||
if (!window.localStorage) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var autoLoginUserId = getParameterByName('u');
|
||||
var storedUserId = localStorage.getItem("userId");
|
||||
|
||||
var storedUserId = store.getItem("userId");
|
||||
|
||||
if (autoLoginUserId && autoLoginUserId != storedUserId) {
|
||||
|
||||
|
@ -118,10 +115,8 @@ var Dashboard = {
|
|||
|
||||
setCurrentUser: function (userId, token) {
|
||||
|
||||
if (window.localStorage) {
|
||||
localStorage.setItem("userId", userId);
|
||||
localStorage.setItem("token", token);
|
||||
}
|
||||
store.setItem("userId", userId);
|
||||
store.setItem("token", token);
|
||||
|
||||
ApiClient.setCurrentUserId(userId, token);
|
||||
Dashboard.getUserPromise = null;
|
||||
|
@ -129,10 +124,8 @@ var Dashboard = {
|
|||
|
||||
logout: function (logoutWithServer) {
|
||||
|
||||
if (window.localStorage) {
|
||||
localStorage.removeItem("userId");
|
||||
localStorage.removeItem("token");
|
||||
}
|
||||
store.removeItem("userId");
|
||||
store.removeItem("token");
|
||||
|
||||
if (logoutWithServer === false) {
|
||||
window.location = "login.html";
|
||||
|
@ -1228,10 +1221,6 @@ var Dashboard = {
|
|||
alert("This browser does not support web sockets. For a better experience, try a newer browser such as Chrome, Firefox, IE10+, Safari (iOS) or Opera.");
|
||||
}
|
||||
|
||||
else if (!IsStorageEnabled()) {
|
||||
alert("This browser does not support local storage or is running in private mode. For a better experience, try a newer browser such as Chrome, Firefox, IE10+, Safari (iOS) or Opera.");
|
||||
}
|
||||
|
||||
window.ApiClient = MediaBrowser.ApiClient.create("Dashboard", window.dashboardVersion);
|
||||
|
||||
$(ApiClient).on("websocketopen", Dashboard.onWebSocketOpened)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
(function (document, $, localStorage) {
|
||||
(function (document, $) {
|
||||
|
||||
var currentOwnerId;
|
||||
var currentThemeIds = [];
|
||||
|
@ -44,7 +44,7 @@
|
|||
|
||||
var userId = Dashboard.getCurrentUserId();
|
||||
|
||||
var val = LocalSettings.val('enableThemeSongs', userId);
|
||||
var val = store.getItem('enableThemeSongs', userId);
|
||||
|
||||
// For bandwidth
|
||||
return val == '1' || (val != '0' && !$.browser.mobile);
|
||||
|
@ -67,4 +67,4 @@
|
|||
}
|
||||
});
|
||||
|
||||
})(document, jQuery, window.localStorage);
|
||||
})(document, jQuery);
|
|
@ -25,7 +25,7 @@
|
|||
shape: "backdrop",
|
||||
preferThumb: true,
|
||||
inheritThumb: false,
|
||||
showParentTitle: true,
|
||||
showParentTitle: false,
|
||||
showUnplayedIndicator: false,
|
||||
showChildCountIndicator: true,
|
||||
overlayText: screenWidth >= 600,
|
||||
|
|
49
dashboard-ui/thirdparty/cast_sender.js
vendored
Normal file
49
dashboard-ui/thirdparty/cast_sender.js
vendored
Normal file
|
@ -0,0 +1,49 @@
|
|||
(function() {var chrome = window.chrome || {};
|
||||
chrome.cast = chrome.cast || {};
|
||||
chrome.cast.media = chrome.cast.media || {};
|
||||
chrome.cast.ApiBootstrap_ = function() {
|
||||
};
|
||||
chrome.cast.ApiBootstrap_.EXTENSION_IDS = ["boadgeojelhgndaghljhdicfkmllpafd", "dliochdbjfkdbacpmhlcpmleaejidimm", "hfaagokkkhdbgiakmmlclaapfelnkoah", "fmfcbgogabcbclcofgocippekhfcmgfj", "enhhojjnijigcajfphajepfemndkmdlo"];
|
||||
chrome.cast.ApiBootstrap_.findInstalledExtension_ = function(callback) {
|
||||
//chrome.cast.ApiBootstrap_.findInstalledExtensionHelper_(0, callback);
|
||||
};
|
||||
chrome.cast.ApiBootstrap_.findInstalledExtensionHelper_ = function(index, callback) {
|
||||
index == chrome.cast.ApiBootstrap_.EXTENSION_IDS.length ? callback(null) : chrome.cast.ApiBootstrap_.isExtensionInstalled_(chrome.cast.ApiBootstrap_.EXTENSION_IDS[index], function(installed) {
|
||||
installed ? callback(chrome.cast.ApiBootstrap_.EXTENSION_IDS[index]) : chrome.cast.ApiBootstrap_.findInstalledExtensionHelper_(index + 1, callback);
|
||||
});
|
||||
};
|
||||
chrome.cast.ApiBootstrap_.getCastSenderUrl_ = function(extensionId) {
|
||||
return "chrome-extension://" + extensionId + "/cast_sender.js";
|
||||
};
|
||||
chrome.cast.ApiBootstrap_.isExtensionInstalled_ = function(extensionId, callback) {
|
||||
var xmlhttp = new XMLHttpRequest;
|
||||
xmlhttp.onreadystatechange = function() {
|
||||
4 == xmlhttp.readyState && 200 == xmlhttp.status && callback(!0);
|
||||
};
|
||||
xmlhttp.onerror = function() {
|
||||
callback(!1);
|
||||
};
|
||||
|
||||
try {
|
||||
// Throws an error in other browsers
|
||||
xmlhttp.open("GET", chrome.cast.ApiBootstrap_.getCastSenderUrl_(extensionId), !0);
|
||||
xmlhttp.send();
|
||||
} catch (ex) {
|
||||
|
||||
}
|
||||
};
|
||||
chrome.cast.ApiBootstrap_.findInstalledExtension_(function(extensionId) {
|
||||
if (extensionId) {
|
||||
console.log("Found cast extension: " + extensionId);
|
||||
chrome.cast.extensionId = extensionId;
|
||||
var apiScript = document.createElement("script");
|
||||
apiScript.src = chrome.cast.ApiBootstrap_.getCastSenderUrl_(extensionId);
|
||||
(document.head || document.documentElement).appendChild(apiScript);
|
||||
} else {
|
||||
var msg = "No cast extension found";
|
||||
console.log(msg);
|
||||
var callback = window.__onGCastApiAvailable;
|
||||
callback && "function" == typeof callback && callback(!1, msg);
|
||||
}
|
||||
});
|
||||
})();
|
Loading…
Add table
Add a link
Reference in a new issue