mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-05-25 12:34:47 -04:00
Refactor view files. Add option to disable sidebar.
This commit is contained in:
parent
2ee4a18e1c
commit
1d2c45dc68
12 changed files with 85 additions and 83 deletions
|
@ -1,7 +1,8 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
* add options to filter/search ignore case
|
* adds option to disable sidebar
|
||||||
* replace PHP `getenv` calls with `$_SERVER` lookups
|
* adds options to filter/search ignore case
|
||||||
|
* replaces PHP `getenv` calls with `$_SERVER` lookups
|
||||||
* adds `view.fallbackMode` option to generally serve only fallback mode
|
* adds `view.fallbackMode` option to generally serve only fallback mode
|
||||||
* serves fallback mode for text browsers (`curl`, `links`, `lynx`, `w3m`)
|
* serves fallback mode for text browsers (`curl`, `links`, `lynx`, `w3m`)
|
||||||
* change type `txt-svg` to `img-svg`, no thumbs but preview
|
* change type `txt-svg` to `img-svg`, no thumbs but preview
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
General view options.
|
General view options.
|
||||||
|
|
||||||
- binaryPrefix: boolean, set to true uses 1024B=1KiB when formatting file sizes (see http://en.wikipedia.org/wiki/Binary_prefix)
|
- binaryPrefix: boolean, set to true uses 1024B=1KiB when formatting file sizes (see http://en.wikipedia.org/wiki/Binary_prefix)
|
||||||
|
- disableSidebar: boolean, hides sidebar and toggle button
|
||||||
- fallbackMode: boolean, serve fallback mode
|
- fallbackMode: boolean, serve fallback mode
|
||||||
- fastBrowsing: boolean, use History API if available (no need to reload the whole page)
|
- fastBrowsing: boolean, use History API if available (no need to reload the whole page)
|
||||||
- fonts: array of strings, fonts to use in regular context
|
- fonts: array of strings, fonts to use in regular context
|
||||||
|
@ -59,6 +60,7 @@
|
||||||
*/
|
*/
|
||||||
"view": {
|
"view": {
|
||||||
"binaryPrefix": false,
|
"binaryPrefix": false,
|
||||||
|
"disableSidebar": false,
|
||||||
"fallbackMode": false,
|
"fallbackMode": false,
|
||||||
"fastBrowsing": true,
|
"fastBrowsing": true,
|
||||||
"fonts": ["Ubuntu", "Roboto", "Helvetica", "Arial", "sans-serif"],
|
"fonts": ["Ubuntu", "Roboto", "Helvetica", "Arial", "sans-serif"],
|
||||||
|
|
|
@ -3,7 +3,7 @@ const event = require('../core/event');
|
||||||
const location = require('../core/location');
|
const location = require('../core/location');
|
||||||
const resource = require('../core/resource');
|
const resource = require('../core/resource');
|
||||||
const allsettings = require('../core/settings');
|
const allsettings = require('../core/settings');
|
||||||
const topbar = require('../view/topbar');
|
const base = require('../view/base');
|
||||||
|
|
||||||
|
|
||||||
const settings = lo.extend({
|
const settings = lo.extend({
|
||||||
|
@ -56,7 +56,7 @@ function init() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$crumbbar = jq('<div id="crumbbar"/>').appendTo(topbar.$flowbar);
|
$crumbbar = jq('<div id="crumbbar"/>').appendTo(base.$flowbar);
|
||||||
|
|
||||||
event.sub('location.changed', onLocationChanged);
|
event.sub('location.changed', onLocationChanged);
|
||||||
}
|
}
|
||||||
|
|
36
src/_h5ai/public/js/lib/view/base.js
Normal file
36
src/_h5ai/public/js/lib/view/base.js
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
const {jq} = require('../globals');
|
||||||
|
|
||||||
|
const rootSelector = 'body';
|
||||||
|
const tplTopbar =
|
||||||
|
`<div id="topbar">
|
||||||
|
<div id="toolbar"/>
|
||||||
|
<div id="flowbar"/>
|
||||||
|
<a id="backlink" href="https://larsjung.de/h5ai/" title="powered by h5ai - https://larsjung.de/h5ai/">
|
||||||
|
<div>powered</div>
|
||||||
|
<div>by h5ai</div>
|
||||||
|
</a>
|
||||||
|
</div>`;
|
||||||
|
const tplMainrow =
|
||||||
|
`<div id="mainrow">
|
||||||
|
<div id="content"/>
|
||||||
|
</div>`;
|
||||||
|
|
||||||
|
const init = () => {
|
||||||
|
jq('#fallback, #fallback-hints').remove();
|
||||||
|
|
||||||
|
const $root = jq(rootSelector)
|
||||||
|
.attr('id', 'root')
|
||||||
|
.append(tplTopbar)
|
||||||
|
.append(tplMainrow);
|
||||||
|
|
||||||
|
return {
|
||||||
|
$root,
|
||||||
|
$topbar: $root.find('#topbar'),
|
||||||
|
$toolbar: $root.find('#toolbar'),
|
||||||
|
$flowbar: $root.find('#flowbar'),
|
||||||
|
$mainrow: $root.find('#mainrow'),
|
||||||
|
$content: $root.find('#content')
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = init();
|
|
@ -1,8 +0,0 @@
|
||||||
const {jq} = require('../globals');
|
|
||||||
const mainrow = require('./mainrow');
|
|
||||||
|
|
||||||
const $el = jq('<div id="content"/>').appendTo(mainrow.$el);
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
$el
|
|
||||||
};
|
|
|
@ -1,8 +0,0 @@
|
||||||
const {jq} = require('../globals');
|
|
||||||
const root = require('./root');
|
|
||||||
|
|
||||||
const $el = jq('<div id="mainrow"/>').appendTo(root.$el);
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
$el
|
|
||||||
};
|
|
|
@ -1,7 +1,7 @@
|
||||||
const {jq} = require('../globals');
|
const {jq} = require('../globals');
|
||||||
const root = require('./root');
|
const base = require('./base');
|
||||||
|
|
||||||
const $el = jq('<div id="notification"/>').hide().appendTo(root.$el);
|
const $el = jq('<div id="notification"/>').hide().appendTo(base.$root);
|
||||||
|
|
||||||
function set(content) {
|
function set(content) {
|
||||||
if (content) {
|
if (content) {
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
const {jq} = require('../globals');
|
|
||||||
|
|
||||||
const $el = jq('body').attr('id', 'root');
|
|
||||||
|
|
||||||
jq('#fallback, #fallback-hints').remove();
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
$el
|
|
||||||
};
|
|
|
@ -1,22 +1,23 @@
|
||||||
const {jq} = require('../globals');
|
const {jq} = require('../globals');
|
||||||
const resource = require('../core/resource');
|
const resource = require('../core/resource');
|
||||||
|
const allsettings = require('../core/settings');
|
||||||
const store = require('../core/store');
|
const store = require('../core/store');
|
||||||
const mainrow = require('./mainrow');
|
const base = require('./base');
|
||||||
const topbar = require('./topbar');
|
|
||||||
|
|
||||||
|
|
||||||
|
const disabled = !!(allsettings.view && allsettings.view.disableSidebar);
|
||||||
const storekey = 'sidebarIsVisible';
|
const storekey = 'sidebarIsVisible';
|
||||||
const tplSidebar = '<div id="sidebar"/>';
|
const tplSidebar = '<div id="sidebar"/>';
|
||||||
const tplToggle =
|
const tplToggle =
|
||||||
`<div id="sidebar-toggle" class="tool">
|
`<div id="sidebar-toggle" class="tool">
|
||||||
<img alt="sidebar"/>
|
<img alt="sidebar"/>
|
||||||
</div>`;
|
</div>`;
|
||||||
|
|
||||||
|
const init = () => {
|
||||||
const $sidebar = jq(tplSidebar);
|
const $sidebar = jq(tplSidebar);
|
||||||
const $toggle = jq(tplToggle);
|
const $toggle = jq(tplToggle);
|
||||||
const $img = $toggle.find('img');
|
const $img = $toggle.find('img');
|
||||||
|
|
||||||
|
const update = toggle => {
|
||||||
function update(toggle) {
|
|
||||||
let isVisible = store.get(storekey);
|
let isVisible = store.get(storekey);
|
||||||
|
|
||||||
if (toggle) {
|
if (toggle) {
|
||||||
|
@ -33,13 +34,19 @@ function update(toggle) {
|
||||||
$img.attr('src', resource.image('sidebar'));
|
$img.attr('src', resource.image('sidebar'));
|
||||||
$sidebar.hide();
|
$sidebar.hide();
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!disabled) {
|
||||||
|
$sidebar.appendTo(base.$mainrow);
|
||||||
|
$toggle.appendTo(base.$toolbar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$toggle.on('click', () => update(true));
|
||||||
$sidebar.appendTo(mainrow.$el);
|
|
||||||
$toggle.appendTo(topbar.$toolbar).on('click', () => update(true));
|
|
||||||
update();
|
update();
|
||||||
|
|
||||||
module.exports = {
|
return {
|
||||||
$el: $sidebar
|
$el: $sidebar
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = init();
|
||||||
|
|
|
@ -1,19 +0,0 @@
|
||||||
const {jq} = require('../globals');
|
|
||||||
const root = require('./root');
|
|
||||||
|
|
||||||
const tplTopbar =
|
|
||||||
`<div id="topbar">
|
|
||||||
<div id="toolbar"/>
|
|
||||||
<div id="flowbar"/>
|
|
||||||
<a id="backlink" href="https://larsjung.de/h5ai/" title="powered by h5ai - https://larsjung.de/h5ai/">
|
|
||||||
<div>powered</div>
|
|
||||||
<div>by h5ai</div>
|
|
||||||
</a>
|
|
||||||
</div>`;
|
|
||||||
const $el = jq(tplTopbar).appendTo(root.$el);
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
$el,
|
|
||||||
$toolbar: $el.find('#toolbar'),
|
|
||||||
$flowbar: $el.find('#flowbar')
|
|
||||||
};
|
|
|
@ -5,7 +5,7 @@ const location = require('../core/location');
|
||||||
const resource = require('../core/resource');
|
const resource = require('../core/resource');
|
||||||
const store = require('../core/store');
|
const store = require('../core/store');
|
||||||
const allsettings = require('../core/settings');
|
const allsettings = require('../core/settings');
|
||||||
const content = require('./content');
|
const base = require('./base');
|
||||||
|
|
||||||
const modes = ['details', 'grid', 'icons'];
|
const modes = ['details', 'grid', 'icons'];
|
||||||
const sizes = [20, 40, 60, 80, 100, 150, 200, 250, 300, 350, 400];
|
const sizes = [20, 40, 60, 80, 100, 150, 200, 250, 300, 350, 400];
|
||||||
|
@ -204,7 +204,7 @@ function setItems(items) {
|
||||||
$items.append(createHtml(e));
|
$items.append(createHtml(e));
|
||||||
});
|
});
|
||||||
|
|
||||||
content.$el.scrollLeft(0).scrollTop(0);
|
base.$content.scrollLeft(0).scrollTop(0);
|
||||||
checkHint();
|
checkHint();
|
||||||
event.pub('view.changed', items, removed);
|
event.pub('view.changed', items, removed);
|
||||||
}
|
}
|
||||||
|
@ -267,7 +267,7 @@ function init() {
|
||||||
addCssStyles();
|
addCssStyles();
|
||||||
set();
|
set();
|
||||||
|
|
||||||
$view.appendTo(content.$el);
|
$view.appendTo(base.$content);
|
||||||
$hint.hide();
|
$hint.hide();
|
||||||
|
|
||||||
format.setDefaultMetric(settings.binaryPrefix);
|
format.setDefaultMetric(settings.binaryPrefix);
|
||||||
|
|
|
@ -3,7 +3,7 @@ const event = require('../core/event');
|
||||||
const resource = require('../core/resource');
|
const resource = require('../core/resource');
|
||||||
const allsettings = require('../core/settings');
|
const allsettings = require('../core/settings');
|
||||||
const sidebar = require('./sidebar');
|
const sidebar = require('./sidebar');
|
||||||
const topbar = require('./topbar');
|
const base = require('./base');
|
||||||
const view = require('./view');
|
const view = require('./view');
|
||||||
|
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ function addToggle() {
|
||||||
if (settings.modeToggle && modes.length > 1) {
|
if (settings.modeToggle && modes.length > 1) {
|
||||||
jq(tplToggle)
|
jq(tplToggle)
|
||||||
.on('click', onToggle)
|
.on('click', onToggle)
|
||||||
.appendTo(topbar.$toolbar);
|
.appendTo(base.$toolbar);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue