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

update sync scripts

This commit is contained in:
Luke Pulverenti 2016-12-10 02:16:15 -05:00
parent ec06f3cc61
commit fc210d8ad2
18 changed files with 1394 additions and 564 deletions

View file

@ -14,12 +14,12 @@
},
"devDependencies": {},
"ignore": [],
"version": "1.4.375",
"_release": "1.4.375",
"version": "1.4.380",
"_release": "1.4.380",
"_resolution": {
"type": "version",
"tag": "1.4.375",
"commit": "728db9b8c27dcea2b8679e4d7ba6f556cfb9dc20"
"tag": "1.4.380",
"commit": "ef70fed326cf70ed366390f05df489943b155c13"
},
"_source": "https://github.com/MediaBrowser/emby-webcomponents.git",
"_target": "^1.2.1",

View file

@ -55,6 +55,11 @@
}
function isStyleSupported(prop, value) {
if (typeof window === 'undefined') {
return false;
}
// If no value is supplied, use "inherit"
value = arguments.length === 2 ? value : 'inherit';
// Try the native standard method first
@ -220,7 +225,7 @@
};
};
var userAgent = window.navigator.userAgent;
var userAgent = navigator.userAgent;
var matched = uaMatch(userAgent);
var browser = {};
@ -248,7 +253,7 @@
}
browser.xboxOne = userAgent.toLowerCase().indexOf('xbox') !== -1;
browser.animate = document.documentElement.animate != null;
browser.animate = typeof document !== 'undefined' && document.documentElement.animate != null;
browser.tizen = userAgent.toLowerCase().indexOf('tizen') !== -1 || userAgent.toLowerCase().indexOf('smarthub') !== -1;
browser.web0s = userAgent.toLowerCase().indexOf('Web0S'.toLowerCase()) !== -1;
browser.edgeUwp = browser.edge && userAgent.toLowerCase().indexOf('msapphost') !== -1;
@ -264,8 +269,10 @@
browser.slow = true;
}
if (('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch) {
browser.touch = true;
if (typeof document !== 'undefined') {
if (('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch) {
browser.touch = true;
}
}
browser.keyboard = hasKeyboard(browser);

View file

@ -0,0 +1,323 @@
// from https://github.com/jakearchibald/idb
(function () {
'use strict';
function toArray(arr) {
return Array.prototype.slice.call(arr);
}
function promisifyRequest(request) {
return new Promise(function (resolve, reject) {
request.onsuccess = function () {
resolve(request.result);
};
request.onerror = function () {
reject(request.error);
};
});
}
function promisifyRequestCall(obj, method, args) {
var request;
var p = new Promise(function (resolve, reject) {
request = obj[method].apply(obj, args);
promisifyRequest(request).then(resolve, reject);
});
p.request = request;
return p;
}
function promisifyCursorRequestCall(obj, method, args) {
var p = promisifyRequestCall(obj, method, args);
return p.then(function (value) {
if (!value) {
return;
}
return new Cursor(value, p.request);
});
}
function proxyProperties(ProxyClass, targetProp, properties) {
properties.forEach(function (prop) {
Object.defineProperty(ProxyClass.prototype, prop, {
get: function () {
return this[targetProp][prop];
}
});
});
}
function proxyRequestMethods(ProxyClass, targetProp, Constructor, properties) {
properties.forEach(function (prop) {
if (!(prop in Constructor.prototype)) {
return;
}
ProxyClass.prototype[prop] = function () {
return promisifyRequestCall(this[targetProp], prop, arguments);
};
});
}
function proxyMethods(ProxyClass, targetProp, Constructor, properties) {
properties.forEach(function (prop) {
if (!(prop in Constructor.prototype)) {
return;
}
ProxyClass.prototype[prop] = function () {
return this[targetProp][prop].apply(this[targetProp], arguments);
};
});
}
function proxyCursorRequestMethods(ProxyClass, targetProp, Constructor, properties) {
properties.forEach(function (prop) {
if (!(prop in Constructor.prototype)) {
return;
}
ProxyClass.prototype[prop] = function () {
return promisifyCursorRequestCall(this[targetProp], prop, arguments);
};
});
}
function Index(index) {
this._index = index;
}
proxyProperties(Index, '_index', [
'name',
'keyPath',
'multiEntry',
'unique'
]);
proxyRequestMethods(Index, '_index', IDBIndex, [
'get',
'getKey',
'getAll',
'getAllKeys',
'count'
]);
proxyCursorRequestMethods(Index, '_index', IDBIndex, [
'openCursor',
'openKeyCursor'
]);
function Cursor(cursor, request) {
this._cursor = cursor;
this._request = request;
}
proxyProperties(Cursor, '_cursor', [
'direction',
'key',
'primaryKey',
'value'
]);
proxyRequestMethods(Cursor, '_cursor', IDBCursor, [
'update',
'delete'
]);
// proxy 'next' methods
['advance', 'continue', 'continuePrimaryKey'].forEach(function (methodName) {
if (!(methodName in IDBCursor.prototype)) {
return;
}
Cursor.prototype[methodName] = function () {
var cursor = this;
var args = arguments;
return Promise.resolve().then(function () {
cursor._cursor[methodName].apply(cursor._cursor, args);
return promisifyRequest(cursor._request).then(function (value) {
if (!value) {
return;
}
return new Cursor(value, cursor._request);
});
});
};
});
function ObjectStore(store) {
this._store = store;
}
ObjectStore.prototype.createIndex = function () {
return new Index(this._store.createIndex.apply(this._store, arguments));
};
ObjectStore.prototype.index = function () {
return new Index(this._store.index.apply(this._store, arguments));
};
proxyProperties(ObjectStore, '_store', [
'name',
'keyPath',
'indexNames',
'autoIncrement'
]);
proxyRequestMethods(ObjectStore, '_store', IDBObjectStore, [
'put',
'add',
'delete',
'clear',
'get',
'getAll',
'getAllKeys',
'count'
]);
proxyCursorRequestMethods(ObjectStore, '_store', IDBObjectStore, [
'openCursor',
'openKeyCursor'
]);
proxyMethods(ObjectStore, '_store', IDBObjectStore, [
'deleteIndex'
]);
function Transaction(idbTransaction) {
this._tx = idbTransaction;
this.complete = new Promise(function (resolve, reject) {
idbTransaction.oncomplete = function () {
resolve();
};
idbTransaction.onerror = function () {
reject(idbTransaction.error);
};
idbTransaction.onabort = function () {
reject(idbTransaction.error);
};
});
}
Transaction.prototype.objectStore = function () {
return new ObjectStore(this._tx.objectStore.apply(this._tx, arguments));
};
proxyProperties(Transaction, '_tx', [
'objectStoreNames',
'mode'
]);
proxyMethods(Transaction, '_tx', IDBTransaction, [
'abort'
]);
function UpgradeDB(db, oldVersion, transaction) {
this._db = db;
this.oldVersion = oldVersion;
this.transaction = new Transaction(transaction);
}
UpgradeDB.prototype.createObjectStore = function () {
return new ObjectStore(this._db.createObjectStore.apply(this._db, arguments));
};
proxyProperties(UpgradeDB, '_db', [
'name',
'version',
'objectStoreNames'
]);
proxyMethods(UpgradeDB, '_db', IDBDatabase, [
'deleteObjectStore',
'close'
]);
function DB(db) {
this._db = db;
}
DB.prototype.transaction = function () {
return new Transaction(this._db.transaction.apply(this._db, arguments));
};
proxyProperties(DB, '_db', [
'name',
'version',
'objectStoreNames'
]);
proxyMethods(DB, '_db', IDBDatabase, [
'close'
]);
// Add cursor iterators
// TODO: remove this once browsers do the right thing with promises
['openCursor', 'openKeyCursor'].forEach(function (funcName) {
[ObjectStore, Index].forEach(function (Constructor) {
Constructor.prototype[funcName.replace('open', 'iterate')] = function () {
var args = toArray(arguments);
var callback = args[args.length - 1];
var nativeObject = this._store || this._index;
var request = nativeObject[funcName].apply(nativeObject, args.slice(0, -1));
request.onsuccess = function () {
callback(request.result);
};
};
});
});
// polyfill getAll
[Index, ObjectStore].forEach(function (Constructor) {
if (Constructor.prototype.getAll) {
return;
}
Constructor.prototype.getAll = function (query, count) {
var instance = this;
var items = [];
return new Promise(function (resolve) {
instance.iterateCursor(query, function (cursor) {
if (!cursor) {
resolve(items);
return;
}
items.push(cursor.value);
if (count !== undefined && items.length === count) {
resolve(items);
return;
}
cursor.continue();
});
});
};
});
var exp = {
open: function (name, version, upgradeCallback) {
var p = promisifyRequestCall(indexedDB, 'open', [name, version]);
var request = p.request;
request.onupgradeneeded = function (event) {
if (upgradeCallback) {
upgradeCallback(new UpgradeDB(request.result, event.oldVersion, request.transaction));
}
};
return p.then(function (db) {
return new DB(db);
});
},
delete: function (name) {
return promisifyRequestCall(indexedDB, 'deleteDatabase', [name]);
}
};
if (typeof module !== 'undefined') {
module.exports = exp;
}
else {
self.idb = exp;
}
}());

View file

@ -353,5 +353,6 @@
"HeaderPlayMyMedia": "Play my Media",
"HeaderDiscoverEmbyPremiere": "Discover Emby Premiere",
"OneChannel": "One channel",
"ConfirmRemoveDownload": "Remove download?",
"AddedOnValue": "Added {0}"
}

View file

@ -0,0 +1,85 @@
define(['itemHelper', 'globalize', 'apphost', 'connectionManager', 'events', 'emby-checkbox'], function (itemHelper, globalize, appHost, connectionManager, events) {
'use strict';
function updateSyncStatus(container, item) {
container.querySelector('.chkOffline').checked = item.SyncPercent != null;
}
function syncToggle(options) {
var self = this;
function resetSyncStatus() {
updateSyncStatus(options.container, options.item);
}
function onSyncLocalClick() {
if (this.checked) {
require(['syncDialog'], function (syncDialog) {
syncDialog.showMenu({
items: [options.item],
isLocalSync: true,
serverId: options.item.ServerId
}).then(function () {
events.trigger(self, 'sync');
}, resetSyncStatus);
});
} else {
require(['confirm'], function (confirm) {
confirm(globalize.translate('sharedcomponents#ConfirmRemoveDownload')).then(function () {
connectionManager.getApiClient(options.item.ServerId).cancelSyncItems([options.item.Id]);
}, resetSyncStatus);
});
}
}
var container = options.container;
var user = options.user;
var item = options.item;
var html = '';
html += '<label class="checkboxContainer" style="margin: 0;">';
html += '<input type="checkbox" is="emby-checkbox" class="chkOffline" />';
html += '<span>' + globalize.translate('sharedcomponents#MakeAvailableOffline') + '</span>';
html += '</label>';
if (itemHelper.canSync(user, item)) {
if (appHost.supports('sync')) {
container.classList.remove('hide');
} else {
container.classList.add('hide');
}
container.innerHTML = html;
container.querySelector('.chkOffline').addEventListener('change', onSyncLocalClick);
updateSyncStatus(container, item);
} else {
container.classList.add('hide');
}
}
syncToggle.prototype.refresh = function(item) {
this.options.item = item;
updateSyncStatus(this.options.container, item);
};
syncToggle.prototype.destroy = function () {
var options = this.options;
if (options) {
options.container.innerHTML = '';
this.options = null;
}
};
return syncToggle;
});