@@ -37,7 +37,7 @@ const setup = config.setup;
const addTest = (label, info, passed, result) => {
- const $test = dom(tplTest).appTo('#tests');
+ const $test = dom(testTpl).appTo('#tests');
$test.find('.label').text(label);
$test.find('.result')
.addCls(passed ? 'passed' : 'failed')
@@ -50,7 +50,7 @@ const addTests = () => {
return;
}
- dom(tplTests).appTo('#content');
+ dom(testsTpl).appTo('#content');
addTest(
'h5ai version', 'Only green if this is an official h5ai release',
@@ -157,11 +157,11 @@ const onKeydown = ev => {
};
const addSupport = () => {
- dom(tplSupport).appTo('#content');
+ dom(supportTpl).appTo('#content');
};
const addLogin = () => {
- dom(tplLogin).appTo('#content');
+ dom(loginTpl).appTo('#content');
if (setup.AS_ADMIN) {
dom('#pass').rm();
diff --git a/src/_h5ai/public/js/lib/view/base.js b/src/_h5ai/public/js/lib/view/base.js
index db958d46..053f000c 100644
--- a/src/_h5ai/public/js/lib/view/base.js
+++ b/src/_h5ai/public/js/lib/view/base.js
@@ -1,7 +1,7 @@
const {dom} = require('../util');
const rootSelector = 'body';
-const tplTopbar =
+const topbarTpl =
`
@@ -10,7 +10,7 @@ const tplTopbar =
by h5ai
`;
-const tplMainrow =
+const mainrowTpl =
`
`;
@@ -20,8 +20,8 @@ const init = () => {
const $root = dom(rootSelector)
.attr('id', 'root')
- .app(tplTopbar)
- .app(tplMainrow);
+ .app(topbarTpl)
+ .app(mainrowTpl);
return {
$root,
diff --git a/src/_h5ai/public/js/lib/view/sidebar.js b/src/_h5ai/public/js/lib/view/sidebar.js
index 344f7461..cfff6652 100644
--- a/src/_h5ai/public/js/lib/view/sidebar.js
+++ b/src/_h5ai/public/js/lib/view/sidebar.js
@@ -9,16 +9,16 @@ const settings = Object.assign({
disableSidebar: false
}, allsettings.view);
const storekey = 'sidebarIsVisible';
-const tplSidebar = '';
-const tplToggle =
+const sidebarTpl = '';
+const toggleTpl =
``;
const init = () => {
- const $sidebar = dom(tplSidebar).hide();
- const $toggle = dom(tplToggle);
+ const $sidebar = dom(sidebarTpl).hide();
+ const $toggle = dom(toggleTpl);
const $img = $toggle.find('img');
const update = toggle => {
diff --git a/src/_h5ai/public/js/lib/view/view.js b/src/_h5ai/public/js/lib/view/view.js
index 556520c6..aff35efb 100644
--- a/src/_h5ai/public/js/lib/view/view.js
+++ b/src/_h5ai/public/js/lib/view/view.js
@@ -21,7 +21,7 @@ const settings = Object.assign({
const sortedSizes = settings.sizes.sort((a, b) => a - b);
const checkedModes = intersection(settings.modes, modes);
const storekey = 'view';
-const tplView =
+const viewTpl =
`
`;
-const tplItem =
+const itemTpl =
`
@@ -43,7 +43,7 @@ const tplItem =
`;
-const $view = dom(tplView);
+const $view = dom(viewTpl);
const $items = $view.find('#items');
const $hint = $view.find('#view-hint');
@@ -55,22 +55,26 @@ const createStyles = size => {
const gsize = cropSize(size, 40, 160);
const isize = cropSize(size, 80, 1000);
const ilsize = Math.round(isize * 4 / 3);
+ const important = '!important;';
+ const detailsPrefix = `#view.view-details.view-size-${size}`;
+ const gridPrefix = `#view.view-grid.view-size-${size}`;
+ const iconsPrefix = `#view.view-icons.view-size-${size}`;
const rules = [
- `#view.view-details.view-size-${size} .item .label {line-height: ${dsize + 14}px !important;}`,
- `#view.view-details.view-size-${size} .item .date {line-height: ${dsize + 14}px !important;}`,
- `#view.view-details.view-size-${size} .item .size {line-height: ${dsize + 14}px !important;}`,
- `#view.view-details.view-size-${size} .square {width: ${dsize}px !important; height: ${dsize}px !important;}`,
- `#view.view-details.view-size-${size} .square img {width: ${dsize}px !important; height: ${dsize}px !important;}`,
- `#view.view-details.view-size-${size} .label {margin-left: ${dsize + 32}px !important;}`,
+ `${detailsPrefix} .item .label {line-height: ${dsize + 14}px ${important}}`,
+ `${detailsPrefix} .item .date {line-height: ${dsize + 14}px ${important}}`,
+ `${detailsPrefix} .item .size {line-height: ${dsize + 14}px ${important}}`,
+ `${detailsPrefix} .square {width: ${dsize}px ${important} height: ${dsize}px ${important}}`,
+ `${detailsPrefix} .square img {width: ${dsize}px ${important} height: ${dsize}px ${important}}`,
+ `${detailsPrefix} .label {margin-left: ${dsize + 32}px ${important}}`,
- `#view.view-grid.view-size-${size} .item .label {line-height: ${gsize}px !important;}`,
- `#view.view-grid.view-size-${size} .square {width: ${gsize}px !important; height: ${gsize}px !important;}`,
- `#view.view-grid.view-size-${size} .square img {width: ${gsize}px !important; height: ${gsize}px !important;}`,
+ `${gridPrefix} .item .label {line-height: ${gsize}px ${important}}`,
+ `${gridPrefix} .square {width: ${gsize}px ${important} height: ${gsize}px ${important}}`,
+ `${gridPrefix} .square img {width: ${gsize}px ${important} height: ${gsize}px ${important}}`,
- `#view.view-icons.view-size-${size} .item {width: ${ilsize}px !important;}`,
- `#view.view-icons.view-size-${size} .landscape {width: ${ilsize}px !important; height: ${isize}px !important;}`,
- `#view.view-icons.view-size-${size} .landscape img {width: ${isize}px !important; height: ${isize}px !important;}`,
- `#view.view-icons.view-size-${size} .landscape .thumb {width: ${ilsize}px !important;}`
+ `${iconsPrefix} .item {width: ${ilsize}px ${important}}`,
+ `${iconsPrefix} .landscape {width: ${ilsize}px ${important} height: ${isize}px ${important}}`,
+ `${iconsPrefix} .landscape img {width: ${isize}px ${important} height: ${isize}px ${important}}`,
+ `${iconsPrefix} .landscape .thumb {width: ${ilsize}px ${important}}`
];
return rules.join('\n');
@@ -129,7 +133,7 @@ const onMouseleave = ev => {
};
const createHtml = item => {
- const $html = dom(tplItem);
+ const $html = dom(itemTpl);
const $a = $html.find('a');
const $iconImg = $html.find('.icon img');
const $label = $html.find('.label');
@@ -243,6 +247,17 @@ const onLocationRefreshed = (item, added, removed) => {
changeItems(add, removed);
};
+const onResize = () => {
+ const width = $view[0].offsetWidth;
+
+ $view.rmCls('width-0').rmCls('width-1');
+ if (width < 320) {
+ $view.addCls('width-0');
+ } else if (width < 480) {
+ $view.addCls('width-1');
+ }
+};
+
const init = () => {
addCssStyles();
set();
@@ -254,9 +269,10 @@ const init = () => {
event.sub('location.changed', onLocationChanged);
event.sub('location.refreshed', onLocationRefreshed);
+ event.sub('resize', onResize);
+ onResize();
};
-
init();
module.exports = {
diff --git a/src/_h5ai/public/js/lib/view/viewmode.js b/src/_h5ai/public/js/lib/view/viewmode.js
index ebcce354..75b64810 100644
--- a/src/_h5ai/public/js/lib/view/viewmode.js
+++ b/src/_h5ai/public/js/lib/view/viewmode.js
@@ -10,15 +10,15 @@ const view = require('./view');
const settings = Object.assign({
modeToggle: false
}, allsettings.view);
-const tplSettings =
+const settingsTpl =
'
View
';
-const tplMode =
+const modeTpl =
`
`;
-const tplSize =
+const sizeTpl =
'
';
-const tplToggle =
+const toggleTpl =
`
`;
@@ -42,11 +42,11 @@ const addSettings = () => {
return;
}
- const $viewBlock = dom(tplSettings);
+ const $viewBlock = dom(settingsTpl);
if (modes.length > 1) {
each(modes, mode => {
- dom(tplMode.replace(/\[MODE\]/g, mode))
+ dom(modeTpl.replace(/\[MODE\]/g, mode))
.on('click', () => {
view.setMode(mode);
})
@@ -56,7 +56,7 @@ const addSettings = () => {
if (sizes.length > 1) {
const max = sizes.length - 1;
- dom(tplSize)
+ dom(sizeTpl)
.attr('max', max)
.on('input', ev => view.setSize(sizes[ev.target.valueAsNumber]))
.on('change', ev => view.setSize(sizes[ev.target.valueAsNumber]))
@@ -76,7 +76,7 @@ const onToggle = () => {
const addToggle = () => {
if (settings.modeToggle && modes.length > 1) {
- dom(tplToggle)
+ dom(toggleTpl)
.on('click', onToggle)
.appTo(base.$toolbar);
}