jellyfin-web/dashboard-ui/bower_components/emby-webcomponents/layoutmanager.js

67 lines
1.9 KiB
JavaScript
Raw Normal View History

2016-05-06 10:49:58 -07:00
define(['browser', 'appSettings', 'events'], function (browser, appSettings, events) {
2016-02-04 11:19:10 -07:00
2016-04-10 21:24:16 -07:00
function setLayout(self, layout, selectedLayout) {
if (layout == selectedLayout) {
self[layout] = true;
document.documentElement.classList.add('layout-' + layout);
} else {
self[layout] = false;
document.documentElement.classList.remove('layout-' + layout);
}
}
2016-02-04 11:19:10 -07:00
function layoutManager() {
var self = this;
2016-04-11 07:05:43 -07:00
self.setLayout = function (layout, save) {
2016-02-04 11:19:10 -07:00
2016-04-11 07:05:43 -07:00
if (!layout || layout == 'auto') {
self.autoLayout();
if (save !== false) {
appSettings.set('layout', '');
}
} else {
setLayout(self, 'mobile', layout);
setLayout(self, 'tv', layout);
setLayout(self, 'desktop', layout);
if (save !== false) {
appSettings.set('layout', layout);
}
}
2016-05-06 10:49:58 -07:00
events.trigger(self, 'modechange');
2016-04-11 07:05:43 -07:00
};
self.getSavedLayout = function (layout) {
return appSettings.get('layout');
2016-04-10 21:24:16 -07:00
};
self.autoLayout = function () {
2016-02-04 11:19:10 -07:00
2016-04-10 21:24:16 -07:00
// Take a guess at initial layout. The consuming app can override
if (browser.mobile) {
2016-04-11 07:05:43 -07:00
self.setLayout('mobile', false);
2016-07-26 22:19:56 -07:00
} else if (browser.tv || browser.xboxOne) {
2016-04-11 07:05:43 -07:00
self.setLayout('tv', false);
2016-04-10 21:24:16 -07:00
} else {
2016-04-11 07:05:43 -07:00
self.setLayout(self.undetectedAutoLayout || 'desktop', false);
2016-04-10 21:24:16 -07:00
}
2016-02-04 11:19:10 -07:00
};
2016-04-11 07:05:43 -07:00
self.init = function () {
var saved = self.getSavedLayout();
if (saved) {
self.setLayout(saved, false);
} else {
self.autoLayout();
}
};
2016-02-04 11:19:10 -07:00
};
return new layoutManager();
});