Skip to content

Commit a733d81

Browse files
committed
feature: css: --is-mobile: add
1 parent 06cf0ee commit a733d81

File tree

5 files changed

+47
-10
lines changed

5 files changed

+47
-10
lines changed

client/client.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,8 @@ function CloudCmdProto(DOM) {
5959
this.prefixSocket = '';
6060
this.prefixURL = '';
6161

62-
const bodyStyle = getComputedStyle(document.body);
63-
64-
this.MIN_ONE_PANEL_WIDTH = bodyStyle.getPropertyValue('--min-one-panel-width');
65-
this.MOBILE_ONE_PANEL_WIDTH = bodyStyle.getPropertyValue('--mobile-max-width');
66-
62+
this.MIN_ONE_PANEL_WIDTH = DOM.getCSSVar('min-one-panel-width');
6763
this.HOST = location.origin || location.protocol + '//' + location.host;
68-
69-
this.TITLE = 'Cloud Commander';
70-
7164
this.sort = {
7265
left: 'name',
7366
right: 'name',

client/dom/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,11 @@ module.exports.getPanelPosition = (panel) => {
520520
return panel.dataset.name.replace('js-', '');
521521
};
522522

523+
module.exports.getCSSVar = (name, {body = document.body} = {}) => {
524+
const bodyStyle = getComputedStyle(body);
525+
return bodyStyle.getPropertyValue(`--${name}`);
526+
};
527+
523528
/** function getting panel active, or passive
524529
* @param options = {active: true}
525530
*/

client/dom/index.spec.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ require('css-modules-require-hook/preset');
44

55
const {test, stub} = require('supertape');
66
const mockRequire = require('mock-require');
7+
const {getCSSVar} = require('./index');
78
const {reRequire, stopAll} = mockRequire;
89

910
global.CloudCmd = {};
@@ -29,3 +30,32 @@ test('cloudcmd: client: dom: goToDirectory', async (t) => {
2930
t.calledWith(changeDir, [path]);
3031
t.end();
3132
});
33+
34+
test('cloudcmd: client: dom: getCSSVar', (t) => {
35+
const body = {};
36+
const getPropertyValue = stub().returns(0);
37+
38+
global.getComputedStyle = stub().returns({
39+
getPropertyValue,
40+
});
41+
const result = getCSSVar('hello', {body});
42+
delete global.getComputedStyle;
43+
44+
t.notOk(result);
45+
t.end();
46+
});
47+
48+
test('cloudcmd: client: dom: getCSSVar: 1', (t) => {
49+
const body = {};
50+
const getPropertyValue = stub().returns(1);
51+
52+
global.getComputedStyle = stub().returns({
53+
getPropertyValue,
54+
});
55+
const result = getCSSVar('hello', {body});
56+
57+
delete global.getComputedStyle;
58+
59+
t.ok(result);
60+
t.end();
61+
});

client/listeners/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,9 @@ function copyPath(el) {
222222
}
223223

224224
function execIfNotMobile(callback, event) {
225-
if (window.innerWidth > CloudCmd.MOBILE_ONE_PANEL_WIDTH)
225+
const isMobile = DOM.getCSSVar('is-mobile');
226+
227+
if (!isMobile)
226228
callback(event);
227229
}
228230

css/query.css

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
width: 15%;
2020
}
2121
}
22+
2223
:root {
23-
--mobile-max-width: 600px;
2424
--min-one-panel-width: 1155px;
25+
--is-mobile: 0;
2526
}
2627

2728
@media only screen and (height <= 900px) and (width <= 600px) {
@@ -56,6 +57,12 @@
5657
}
5758
}
5859

60+
@media only screen and (width <= 600px) {
61+
:root {
62+
--is-mobile: 1;
63+
}
64+
}
65+
5966
@media only screen and (height <= 550px) and (width <= 600px) {
6067
.fm {
6168
height: 65%;

0 commit comments

Comments
 (0)